From da4b75c99383957b3974b019a28dd1777765fe6d Mon Sep 17 00:00:00 2001 From: Jelle Henkens Date: Fri, 26 Aug 2011 22:16:49 +0100 Subject: [PATCH 01/24] Fixing issue where the time helper sets the wrong timezone part in RSS dates --- cake/libs/view/helpers/time.php | 11 +++++++++++ cake/tests/cases/libs/view/helpers/time.test.php | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index 232841bb6..630515fd0 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -440,6 +440,17 @@ class TimeHelper extends AppHelper { */ function toRSS($dateString, $userOffset = null) { $date = $this->fromString($dateString, $userOffset); + + if(!is_null($userOffset)) { + if($userOffset == 0) { + $timezone = '+0000'; + } else { + $hours = (int) floor(abs($userOffset)); + $minutes = (int) (fmod(abs($userOffset), $hours) * 60); + $timezone = ($userOffset < 0 ? '-' : '+') . str_pad($hours, 2, '0', STR_PAD_LEFT) . str_pad($minutes, 2, '0', STR_PAD_LEFT); + } + return date('D, d M Y H:i:s', $date) . ' ' . $timezone; + } return date("r", $date); } diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index daa77f678..1feae5cea 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -409,6 +409,16 @@ class TimeHelperTest extends CakeTestCase { */ function testToRss() { $this->assertEqual(date('r'), $this->Time->toRss(time())); + + if (!$this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) { + $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); + foreach($timezones as $timezone) { + $yourTimezone = new DateTimeZone($timezone); + $yourTime = new DateTime('now', $yourTimezone); + $userOffset = $yourTimezone->getOffset($yourTime) / HOUR; + $this->assertEqual($yourTime->format('r'), $this->Time->toRss(time(), $userOffset)); + } + } } /** From 53d221c3d17ac273a0a6fdc313d8fa8c6f6ece61 Mon Sep 17 00:00:00 2001 From: Jelle Henkens Date: Mon, 5 Sep 2011 01:21:38 +0100 Subject: [PATCH 02/24] Fixing bug where scientific notations were not passed to mysql in their original form which resulted in loss of precision --- cake/libs/model/datasources/dbo/dbo_mysql.php | 2 +- .../model/datasources/dbo/dbo_mysql.test.php | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 70367b9bc..5ac4013c8 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -672,7 +672,7 @@ class DboMysql extends DboMysqlBase { return 'NULL'; } if (is_float($data)) { - return sprintf('%F', $data); + return str_replace(',', '.', sprintf('%G', $data)); } if ((is_int($data) || $data === '0') || ( is_numeric($data) && strpos($data, ',') === false && diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index d94db8ed0..2cdc6ea73 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -239,14 +239,33 @@ class DboMysqlTest extends CakeTestCase { setlocale(LC_ALL, 'de_DE'); $result = $this->db->value(3.141593, 'float'); - $this->assertEqual((string)$result, '3.141593'); - + $this->assertTrue(strpos((string)$result, ',') === false); + $result = $this->db->value(3.141593); - $this->assertEqual((string)$result, '3.141593'); + $this->assertTrue(strpos((string)$result, ',') === false); + + $result = $this->db->value(2.2E-54, 'float'); + $this->assertEqual('2.2E-54', (string)$result); + + $result = $this->db->value(2.2E-54); + $this->assertEqual('2.2E-54', (string)$result); setlocale(LC_ALL, $restore); } +/** + * test that scientific notations are working correctly + * + * @return void + */ + function testScientificNotation() { + $result = $this->db->value(2.2E-54, 'float'); + $this->assertEqual('2.2E-54', (string)$result); + + $result = $this->db->value(2.2E-54); + $this->assertEqual('2.2E-54', (string)$result); + } + /** * testTinyintCasting method * From 2c3fa32a5de081c6e2710e9804640d81157d626d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 4 Sep 2011 17:50:18 +0100 Subject: [PATCH 03/24] Splitting big test up into smaller ones. --- cake/tests/cases/libs/view/helpers/time.test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 1feae5cea..edcb62750 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -17,9 +17,6 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { - define('CAKEPHP_UNIT_TEST_EXECUTION', 1); -} App::import('Helper', 'Time'); /** From b1c4b57d85308e10d490688030edeaa2eaa113f5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 6 Sep 2011 08:00:08 -0400 Subject: [PATCH 04/24] Updating doc comment about find(list). Refs #1968 --- cake/libs/model/model.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index f25c0318e..f595b7529 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -2056,6 +2056,9 @@ class Model extends Overloadable { * - If three fields are specified, they are used (in order) for key, value and group. * - Otherwise, first and second fields are used for key and value. * + * Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you + * have issues with database views. + * * @param array $conditions SQL conditions array, or type of find operation (all / first / count / * neighbors / list / threaded) * @param mixed $fields Either a single string of a field name, or an array of field names, or From a61bd5e3e8ef6dffb71ef3ab22f20836f2918f18 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 7 Sep 2011 07:18:47 -0400 Subject: [PATCH 05/24] Adding tests for unix socket support in Memcache. Refs GH#194 --- cake/tests/cases/libs/cache/memcache.test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index c43d8ace7..d9e20f6da 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -187,6 +187,17 @@ class MemcacheEngineTest extends CakeTestCase { $this->assertEqual($result, array('sülül', '1111')); } +/** + * test unix sockets. + * + * @return void + */ + function testParseServerStringUnix() { + $Memcache =& new TestMemcacheEngine(); + $result = $Memcache->parseServerString('unix:///path/to/memcached.sock'); + $this->assertEqual($result, array('unix:///path/to/memcached.sock', 0)); + } + /** * testReadAndWriteCache method * From 5e7509be55a0fc0f6727fda469e4b58da1438946 Mon Sep 17 00:00:00 2001 From: T0aD Date: Sun, 4 Sep 2011 04:56:32 +0200 Subject: [PATCH 06/24] Add unix sockets support to memcache. --- cake/libs/cache/memcache.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index 3ae5351f7..a86130705 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -94,12 +94,15 @@ class MemcacheEngine extends CacheEngine { /** * Parses the server address into the host/port. Handles both IPv6 and IPv4 - * addresses + * addresses and Unix sockets * * @param string $server The server address string. * @return array Array containing host, port */ function _parseServerString($server) { + if ($server[0] == 'u') { + return array($server, 0); + } if (substr($server, 0, 1) == '[') { $position = strpos($server, ']:'); if ($position !== false) { From 73a6ebea8d109e34c9218abb88983f78bce75830 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 7 Sep 2011 20:12:22 -0400 Subject: [PATCH 07/24] Add cross version constants. Add constants for older versions of PHP which may be missing them. Fixes #1975 --- cake/basics.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cake/basics.php b/cake/basics.php index dc4f4461d..907dd2717 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -31,6 +31,26 @@ define('MONTH', 2592000); define('YEAR', 31536000); +/** + * Patch old versions of PHP4. + */ +if (!defined('PHP_EOL')) { + switch (strtoupper(substr(PHP_OS, 0, 3))) { + case 'WIN': + define('PHP_EOL', "\r\n"); + break; + default: + define('PHP_EOL', "\n"); + } +} + +/** + * Patch PHP4 and PHP5.0 + */ +if (!defined('DATE_RFC2822')) { + define('DATE_RFC2822', 'D, d M Y H:i:s O'); +} + /** * Patch for PHP < 5.0 */ From 95b275dc3b279a665666e0c0c9f9557691d823b3 Mon Sep 17 00:00:00 2001 From: Daniel Feinberg Date: Wed, 31 Aug 2011 00:10:59 -0600 Subject: [PATCH 08/24] Adding a test that fails for ticket #1762 Signed-off-by: mark_story --- .../libs/model/behaviors/containable.test.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/behaviors/containable.test.php b/cake/tests/cases/libs/model/behaviors/containable.test.php index bfa5a26eb..239fd9252 100644 --- a/cake/tests/cases/libs/model/behaviors/containable.test.php +++ b/cake/tests/cases/libs/model/behaviors/containable.test.php @@ -36,7 +36,7 @@ class ContainableBehaviorTest extends CakeTestCase { */ var $fixtures = array( 'core.article', 'core.article_featured', 'core.article_featureds_tags', 'core.articles_tag', 'core.attachment', 'core.category', - 'core.comment', 'core.featured', 'core.tag', 'core.user' + 'core.comment', 'core.featured', 'core.tag', 'core.user', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_c', 'core.join_a_b' ); /** @@ -3406,6 +3406,21 @@ class ContainableBehaviorTest extends CakeTestCase { $this->assertEqual($expected, array_keys($result)); $this->assertTrue(empty($this->Article->hasMany['ArticlesTag'])); + + $this->JoinA =& ClassRegistry::init('JoinA'); + $this->JoinB =& ClassRegistry::init('JoinB'); + $this->JoinC =& ClassRegistry::init('JoinC'); + + $this->JoinA->Behaviors->attach('Containable'); + $this->JoinB->Behaviors->attach('Containable'); + $this->JoinC->Behaviors->attach('Containable'); + + $this->JoinA->JoinB->find('all', array('contain' => array('JoinA'))); + $this->JoinA->bindModel(array('hasOne' => array('JoinAsJoinC' => array('joinTable' => 'as_cs'))), false); + $result = $this->JoinA->hasOne; + $this->JoinA->find('all'); + $resultAfter = $this->JoinA->hasOne; + $this->assertEqual($result, $resultAfter); } /** From ac0b2b8280a39e27fefe1050783e67867b10c91f Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 7 Sep 2011 20:39:12 -0400 Subject: [PATCH 09/24] Applying patch from Daniel Feinberg for Containable Removes __backContainableAssociation as its not needed and causes more problems than it solves. Fixes #1762 --- cake/libs/model/behaviors/containable.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/cake/libs/model/behaviors/containable.php b/cake/libs/model/behaviors/containable.php index aaab3547e..2c1daf72b 100644 --- a/cake/libs/model/behaviors/containable.php +++ b/cake/libs/model/behaviors/containable.php @@ -147,8 +147,6 @@ class ContainableBehavior extends ModelBehavior { if (!empty($unbind)) { if (!$reset && empty($instance->__backOriginalAssociation)) { $instance->__backOriginalAssociation = $backupBindings; - } else if ($reset && empty($instance->__backContainableAssociation)) { - $instance->__backContainableAssociation = $backupBindings; } $instance->unbindModel(array($type => $unbind), $reset); } @@ -219,24 +217,6 @@ class ContainableBehavior extends ModelBehavior { return $query; } -/** - * Resets original associations on models that may have receive multiple, - * subsequent unbindings. - * - * @param object $Model Model on which we are resetting - * @param array $results Results of the find operation - * @param bool $primary true if this is the primary model that issued the find operation, false otherwise - * @access public - */ - function afterFind(&$Model, $results, $primary) { - if (!empty($Model->__backContainableAssociation)) { - foreach ($Model->__backContainableAssociation as $relation => $bindings) { - $Model->{$relation} = $bindings; - unset($Model->__backContainableAssociation); - } - } - } - /** * Unbinds all relations from a model except the specified ones. Calling this function without * parameters unbinds all related models. From ae942a7f7bf15beb9e03ee576d09713d7d52dbe0 Mon Sep 17 00:00:00 2001 From: Jelle Henkens Date: Wed, 7 Sep 2011 23:38:46 +0100 Subject: [PATCH 10/24] Added tests to test ajax settings --- .../cases/libs/view/helpers/form.test.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 9090bad1a..a2e3684bd 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -5755,6 +5755,37 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $this->Form->request->data = array(); + $this->Form->request['controller'] = 'contacts'; + $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact')); + $result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false)); + $expected = array( + 'form' => array( + 'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param', + 'accept-charset' => 'utf-8' + ), + 'div' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/div' + ); + $this->assertTags($result, $expected); + + $this->Form->request->data = array(); + $this->Form->request['controller'] = 'contacts'; + $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact')); + $result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false, 'onsubmit' => 'someFunction();')); + + $expected = array( + 'form' => array( + 'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'someFunction(); event.returnValue = false; return false;', 'action' => '/contacts/index/param', + 'accept-charset' => 'utf-8' + ), + 'div' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/div' + ); + $this->assertTags($result, $expected); } /** From 31b07795b2ae65494758a770d932b868264e2b5e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 7 Sep 2011 20:57:28 -0400 Subject: [PATCH 11/24] Fix create() and onsubmit option. Backporting bug-fix from 2.0 Removing support for onSubmit variant. Additional choices are not necessary. Fixing onsubmit option not correctly working. Fixes #1977 Conflicts: cake/libs/view/helpers/form.php --- cake/libs/view/helpers/form.php | 16 +++++----- .../cases/libs/view/helpers/form.test.php | 30 ++++++++++++++----- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 0dbaec02c..ecf4ede20 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -173,8 +173,11 @@ class FormHelper extends AppHelper { * * - `type` Form method defaults to POST * - `action` The controller action the form submits to, (optional). - * - `url` The url the form submits to. Can be a string or a url array, - * - `default` Allows for the creation of Ajax forms. + * - `url` The url the form submits to. Can be a string or a url array. If you use 'url' + * you should leave 'action' undefined. + * - `default` Allows for the creation of Ajax forms. Set this to false to prevent the default event handler. + * Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression + * will be appended. * - `onsubmit` Used in conjunction with 'default' to create ajax forms. * - `inputDefaults` set the default $options for FormHelper::input(). Any options that would * be set when using FormHelper::input() can be set here. Options set with `inputDefaults` @@ -294,19 +297,18 @@ class FormHelper extends AppHelper { unset($options['type'], $options['action']); if ($options['default'] == false) { - if (isset($htmlAttributes['onSubmit']) || isset($htmlAttributes['onsubmit'])) { - $htmlAttributes['onsubmit'] .= ' event.returnValue = false; return false;'; - } else { - $htmlAttributes['onsubmit'] = 'event.returnValue = false; return false;'; + if (!isset($options['onsubmit'])) { + $options['onsubmit'] = ''; } + $htmlAttributes['onsubmit'] = $options['onsubmit'] . 'event.returnValue = false; return false;'; } + unset($options['default']); if (!empty($options['encoding'])) { $htmlAttributes['accept-charset'] = $options['encoding']; unset($options['encoding']); } - unset($options['default']); $htmlAttributes = array_merge($options, $htmlAttributes); $this->fields = array(); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index a2e3684bd..c1049ec67 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -5756,9 +5756,17 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Form->request->data = array(); - $this->Form->request['controller'] = 'contacts'; - $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact')); + } + +/** + * Test the onsubmit option for create() + * + * @return void + */ + public function testCreateOnSubmit() { + $this->Form->data = array(); + $this->Form->params['controller'] = 'contacts'; + $this->Form->params['models'] = array('Contact'); $result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false)); $expected = array( 'form' => array( @@ -5771,14 +5779,20 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Form->request->data = array(); - $this->Form->request['controller'] = 'contacts'; - $this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact')); - $result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false, 'onsubmit' => 'someFunction();')); + $this->Form->data = array(); + $this->Form->params['controller'] = 'contacts'; + $this->Form->params['models'] = array('Contact'); + $result = $this->Form->create(array( + 'url' => array('action' => 'index', 'param'), + 'default' => false, + 'onsubmit' => 'someFunction();' + )); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'someFunction(); event.returnValue = false; return false;', 'action' => '/contacts/index/param', + 'id' => 'ContactAddForm', 'method' => 'post', + 'onsubmit' => 'someFunction();event.returnValue = false; return false;', + 'action' => '/contacts/index/param', 'accept-charset' => 'utf-8' ), 'div' => array('style' => 'display:none;'), From 200c85c7c4a1e0d11388b635e4ab55a1277b3e73 Mon Sep 17 00:00:00 2001 From: zoydsan Date: Wed, 7 Sep 2011 01:49:07 +0300 Subject: [PATCH 12/24] Ticket #1669, i18n: parse (multiline) strings concatenated with "." (for 1.3 branch) The patch builds on the code of cake 2.0, but with this fix, comments are allowed, and an exception is thrown if invalid output is found. Examples: __('Split' . ' string') => ok __('Split' . // Comment ' string') => ok __('Split' . $var) => error --- cake/console/libs/tasks/extract.php | 50 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index dd83092d5..4d1ac4aea 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -286,24 +286,13 @@ class ExtractTask extends Shell { } $mapCount = count($map); - $strings = array(); - while (count($strings) < $mapCount && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { - if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { - $strings[] = $this->__tokens[$position][1]; - } - $position++; - } + $strings = $this->__getStrings($position, $mapCount); if ($mapCount == count($strings)) { extract(array_combine($map, $strings)); - if (!isset($domain)) { - $domain = '\'default\''; - } - $string = $this->__formatString($singular); - if (isset($plural)) { - $string .= "\0" . $this->__formatString($plural); - } - $this->__strings[$this->__formatString($domain)][$string][$this->__file][] = $line; + $domain = isset($domain) ? $domain : 'default'; + $string = isset($plural) ? $singular . "\0" . $plural : $singular; + $this->__strings[$domain][$string][$this->__file][] = $line; } else { $this->__markerError($this->__file, $line, $functionName, $count); } @@ -312,6 +301,37 @@ class ExtractTask extends Shell { } } +/** +* Get the strings from the position forward +* +* @param integer $position Actual position on tokens array +* @param integer $target Number of strings to extract +* @return array Strings extracted +*/ + function __getStrings($position, $target) { + $strings = array(); + while (count($strings) < $target && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { + $condition1 = ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1] == '.'); + $condition2 = ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1][0] == T_COMMENT); + if ($condition1 || $condition2) { + $string = ''; + while ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->__tokens[$position][0] == T_COMMENT || $this->__tokens[$position] == '.') { + if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $string .= $this->__formatString($this->__tokens[$position][1]); + } + $position++; + } + if ($this->__tokens[$position][0] == T_COMMENT || $this->__tokens[$position] == ',' || $this->__tokens[$position] == ')') { + $strings[] = $string; + } + } else if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $strings[] = $this->__formatString($this->__tokens[$position][1]); + } + $position++; + } + return $strings; + } + /** * Build the translate template file contents out of obtained strings * From cd14874b5969bc7c8932b7d2228e76ad253cb4c9 Mon Sep 17 00:00:00 2001 From: zoydsan Date: Thu, 8 Sep 2011 17:54:13 +0300 Subject: [PATCH 13/24] Backport unit tests from branch 2.0 (tests for strings concatenated with '.') --- .../cases/console/libs/tasks/extract.test.php | 14 +++++++++++++- cake/tests/test_app/views/pages/extract.ctp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index d071c5869..fbbbd9e17 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -139,6 +139,18 @@ class ExtractTaskTest extends CakeTestCase { $pattern .= 'msgid "Editing this Page"\nmsgstr ""/'; $this->assertPattern($pattern, $result); + $pattern = '/\#: (\\\\|\/)extract\.ctp:17\nmsgid "'; + $pattern .= 'Hot features!'; + $pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin'; + $pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake'; + $pattern .= '\\\n - Active, Friendly Community: Join us #cakephp on IRC. We\'d love to help you get started'; + $pattern .= '"\nmsgstr ""/'; + $this->assertPattern($pattern, $result); + + $pattern = '/\#: (\\\\|\/)extract\.ctp:26\n'; + $pattern .= 'msgid "Found "/'; + $this->assertNoPattern($pattern, $result); + // extract.ctp - reading the domain.pot $result = file_get_contents($path . DS . 'domain.pot'); @@ -156,7 +168,7 @@ class ExtractTaskTest extends CakeTestCase { $Folder->delete(); } function getTests() { - return array('start', 'startCase', 'testExtractMultiplePaths', 'endCase', 'end'); + return array('start', 'startCase', 'testExecute', 'testExtractMultiplePaths', 'endCase', 'end'); } /** diff --git a/cake/tests/test_app/views/pages/extract.ctp b/cake/tests/test_app/views/pages/extract.ctp index e3eede1c1..4eed4a6f5 100644 --- a/cake/tests/test_app/views/pages/extract.ctp +++ b/cake/tests/test_app/views/pages/extract.ctp @@ -11,4 +11,16 @@ __dn('domain', 'You have %d new message (domain).', 'You have %d new messages (d __dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages (domain).', $messages['count']); // Duplicated Message -__('Editing this Page'); \ No newline at end of file +__('Editing this Page'); + +// Multiline with comments +__('Hot features!' + . "\n - No Configuration:" // Comments will be stripped + . ' Set-up the database and let the magic begin' + . "\n - Extremely Simple:" // Comments will be stripped + . ' Just look at the name...It\'s Cake' + . "\n - Active, Friendly Community:" // Comments will be stripped + . ' Join us #cakephp on IRC. We\'d love to help you get started'); + +// This throws an error and is not parsed +__('Found ' . $count . ' new messages'); \ No newline at end of file From 1e1671ab7fc28532cec14808fcbd19b321ff21b8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 Sep 2011 19:53:38 -0400 Subject: [PATCH 14/24] Removing getTests. Fixing failing test. --- cake/tests/cases/console/libs/tasks/extract.test.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index fbbbd9e17..2a2a2fc2e 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -135,7 +135,7 @@ class ExtractTaskTest extends CakeTestCase { $this->assertPattern($pattern, $result); $pattern = '/\#: (\\\\|\/)extract\.ctp:14\n'; - $pattern .= '\#: (\\\\|\/)home\.ctp:74\n'; + $pattern .= '\#: (\\\\|\/)home\.ctp:77\n'; $pattern .= 'msgid "Editing this Page"\nmsgstr ""/'; $this->assertPattern($pattern, $result); @@ -167,9 +167,6 @@ class ExtractTaskTest extends CakeTestCase { $Folder = new Folder($path); $Folder->delete(); } - function getTests() { - return array('start', 'startCase', 'testExecute', 'testExtractMultiplePaths', 'endCase', 'end'); - } /** * test extract can read more than one path. From da6a5fa301cb1d30c12bf9d3fb1d76f5e9288336 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 Sep 2011 20:09:48 -0400 Subject: [PATCH 15/24] Fixing failing tests for float formatting. --- cake/tests/cases/libs/model/datasources/dbo_source.test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 2c06d70cb..f287647d1 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2548,11 +2548,11 @@ class DboSourceTest extends CakeTestCase { $this->assertEqual($result, $expected); $result = $this->testDb->conditions(array('score BETWEEN ? AND ?' => array(90.1, 95.7))); - $expected = " WHERE `score` BETWEEN 90.100000 AND 95.700000"; + $expected = " WHERE `score` BETWEEN 90.1 AND 95.7"; $this->assertEqual($result, $expected); $result = $this->testDb->conditions(array('Post.title' => 1.1)); - $expected = " WHERE `Post`.`title` = 1.100000"; + $expected = " WHERE `Post`.`title` = 1.1"; $this->assertEqual($result, $expected); $result = $this->testDb->conditions(array('Post.title' => 1.1), true, true, new Post()); From 63902ab73f479984667cdf2cb08fe64ffe4a1a4e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 Sep 2011 20:11:09 -0400 Subject: [PATCH 16/24] Adding failing test for similar to. Refs #1979 --- cake/tests/cases/libs/model/datasources/dbo_source.test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index f287647d1..4941b4be2 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2395,6 +2395,12 @@ class DboSourceTest extends CakeTestCase { $result = $this->testDb->conditions($conditions); $expected = " WHERE `Artist`.`name` = 'JUDY AND MARY'"; $this->assertEqual($result, $expected); + + $conditions = array('Company.name similar to ' => 'a word'); + $result = $this->testDb->conditions($conditions); + $expected = " WHERE `Company`.`name` similar to 'a word'"; + $this->assertEqual($result, $expected); + } /** From e86ae437960bb4614a400cfa1d8ea1d42b9df507 Mon Sep 17 00:00:00 2001 From: hirata Date: Thu, 8 Sep 2011 10:56:05 +0900 Subject: [PATCH 17/24] Fix SQL when using operator SIMILAR TO Fixes #1979 --- cake/libs/model/datasources/dbo_source.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index c1c6a02b5..a3206651d 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2239,8 +2239,8 @@ class DboSource extends DataSource { * @access private */ function __parseKey(&$model, $key, $value) { - $operatorMatch = '/^((' . implode(')|(', $this->__sqlOps); - $operatorMatch .= '\\x20)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; + $operatorMatch = '/^(((' . implode(')|(', $this->__sqlOps); + $operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; $bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false)); if (!strpos($key, ' ')) { From fbc76f195ffef8553c43b125708baa0cd927a31a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 Sep 2011 20:17:51 -0400 Subject: [PATCH 18/24] Fixing other failing test. This test was failing because of changes made to Configure + error handling. --- cake/tests/cases/libs/model/datasources/dbo_source.test.php | 1 - 1 file changed, 1 deletion(-) 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 4941b4be2..3b7137ecf 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4172,7 +4172,6 @@ class DboSourceTest extends CakeTestCase { Configure::write('debug', 2); $this->testDb->error = true; - $this->expectError(); ob_start(); $this->testDb->showQuery('Error 2'); $contents = ob_get_clean(); From 60981fcb4bedd3b8929caafc23031bde67313f7a Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 9 Sep 2011 21:35:44 -0400 Subject: [PATCH 19/24] Hardcoding 'app' in JsHelper Applying patch from 'Jelle Henkens'. Hardcoding this value fixes issues where the variable name would change if you renamed your app directory. Fixes environment specific bugs. Fixes #1981 --- cake/libs/view/helpers/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 42f20e218..a41ca6fc3 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -76,7 +76,7 @@ class JsHelper extends AppHelper { * @var string * @access public */ - var $setVariable = APP_DIR; + var $setVariable = 'app'; /** * Constructor - determines engine helper From 707c0b4130877c07967c210b07ec75995e05f818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Fri, 16 Sep 2011 15:06:10 +0200 Subject: [PATCH 20/24] Fixed bug in CakeSchema where it determines the field position. - Respective tests were added. - Schema files will now have 'after' => 'previous_field' on it. --- cake/libs/model/cake_schema.php | 2 +- cake/tests/cases/libs/model/cake_schema.test.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 940b4a1f3..2944e6aff 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -491,7 +491,7 @@ class CakeSchema extends Object { } } - if (isset($add[$table][$field])) { + if (isset($tables[$table]['add'][$field]) && $field !== 'indexes' && $field !== 'tableParameters') { $wrapper = array_keys($fields); if ($column = array_search($field, $wrapper)) { if (isset($wrapper[$column - 1])) { diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 65ca3ce59..3e646145d 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -741,8 +741,8 @@ class CakeSchemaTest extends CakeTestCase { $expected = array( 'comments' => array( 'add' => array( - 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0), - 'title' => array('type' => 'string', 'null' => false, 'length' => 100), + 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'after' => 'id'), + 'title' => array('type' => 'string', 'null' => false, 'length' => 100, 'after' => 'user_id'), ), 'drop' => array( 'article_id' => array('type' => 'integer', 'null' => false), @@ -754,7 +754,7 @@ class CakeSchemaTest extends CakeTestCase { ), 'posts' => array( 'add' => array( - 'summary' => array('type' => 'text', 'null' => 1), + 'summary' => array('type' => 'text', 'null' => 1, 'after' => 'body'), ), 'drop' => array( 'tableParameters' => array(), @@ -795,11 +795,11 @@ class CakeSchemaTest extends CakeTestCase { 'ratings' => array( 'add' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL), - 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL), - 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'id'), + 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL, 'after' => 'foreign_key'), + 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL, 'after' => 'model'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'value'), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'created'), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') ) From 77b3e63293724a0e3d0f5c1bef558c4ca9cd9fb3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 16 Sep 2011 21:12:11 -0400 Subject: [PATCH 21/24] Removing AFTER in Postgres add column. It causes SQL errors on Postgres 8.4 --- cake/libs/model/datasources/dbo/dbo_postgres.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 06a0cc0cc..188912c47 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -580,11 +580,7 @@ class DboPostgres extends DboSource { case 'add': foreach ($column as $field => $col) { $col['name'] = $field; - $alter = 'ADD COLUMN '.$this->buildColumn($col); - if (isset($col['after'])) { - $alter .= ' AFTER '. $this->name($col['after']); - } - $colList[] = $alter; + $colList[] = 'ADD COLUMN '.$this->buildColumn($col); } break; case 'drop': From c919b73f22012c514832a71f21c87f2de706624d Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 16 Sep 2011 21:19:12 -0400 Subject: [PATCH 22/24] Adding failing test for postgres alter table. Refs #1967 --- .../model/datasources/dbo/dbo_postgres.test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index 1f80ef2bc..2f3b9791d 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -699,6 +699,22 @@ class DboPostgresTest extends CakeTestCase { $this->assertEqual($result['title']['null'], false); $this->db->query($this->db->dropSchema($New)); + + $New =& new CakeSchema(array( + 'connection' => 'test_suite', + 'name' => 'AlterPosts', + 'alter_posts' => array( + 'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'), + 'author_id' => array('type' => 'integer', 'null' => false), + 'title' => array('type' => 'string', 'null' => true), + 'body' => array('type' => 'text'), + 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'), + 'created' => array('type' => 'datetime'), + 'updated' => array('type' => 'datetime'), + ) + )); + $result = $this->db->alterSchema($New->compare($Old), 'alter_posts'); + $this->assertNoPattern('/varchar\(36\) NOT NULL/i', $result); } /** From 26495b36d13ba751e2de320cdc4f41d8464448ea Mon Sep 17 00:00:00 2001 From: An M - kub2 Date: Sun, 4 Sep 2011 20:38:38 -0430 Subject: [PATCH 23/24] Fix incorrect formation of query string removed on ALTER COLUMN xx TYPE xxx for postgres. Fixes #1967 --- cake/libs/model/datasources/dbo/dbo_postgres.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 188912c47..1de5a7486 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -599,8 +599,7 @@ class DboPostgres extends DboSource { $default = isset($col['default']) ? $col['default'] : null; $nullable = isset($col['null']) ? $col['null'] : null; unset($col['default'], $col['null']); - $colList[] = 'ALTER COLUMN '. $fieldName .' TYPE ' . str_replace($fieldName, '', $this->buildColumn($col)); - + $colList[] = 'ALTER COLUMN '. $fieldName .' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)); if (isset($nullable)) { $nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL'; $colList[] = 'ALTER COLUMN '. $fieldName .' ' . $nullable; From 26d80debcd228d829f9de301cb8516c8063a523b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 17 Sep 2011 16:46:32 -0400 Subject: [PATCH 24/24] Adding test case for functions in condition keys. Closes #1718 --- cake/tests/cases/libs/model/datasources/dbo_source.test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 3b7137ecf..f092f2dd8 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2573,6 +2573,10 @@ class DboSourceTest extends CakeTestCase { $expected = " WHERE MAX(`Post`.`rating`) > '50'"; $this->assertEqual($result, $expected); + $result = $this->testDb->conditions(array('lower(Article.title)' => 'secrets')); + $expected = " WHERE lower(`Article`.`title`) = 'secrets'"; + $this->assertEqual($result, $expected); + $result = $this->testDb->conditions(array('title LIKE' => '%hello')); $expected = " WHERE `title` LIKE '%hello'"; $this->assertEqual($result, $expected);