From 5f87f74b0958718d4071079cd2e0a8dc508c7f66 Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 3 Aug 2009 20:53:50 +0000 Subject: [PATCH 01/19] setting version to 1.2.4.8284 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8284 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/VERSION.txt | 2 +- cake/config/config.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/VERSION.txt b/cake/VERSION.txt index e210b41c1..a9aa04470 100644 --- a/cake/VERSION.txt +++ b/cake/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -1.2.3.8166 \ No newline at end of file +1.2.4.8284 \ No newline at end of file diff --git a/cake/config/config.php b/cake/config/config.php index 446aea182..24718485b 100644 --- a/cake/config/config.php +++ b/cake/config/config.php @@ -22,5 +22,5 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ -return $config['Cake.version'] = '1.2.3.8166'; +return $config['Cake.version'] = '1.2.4.8284'; ?> \ No newline at end of file From 9363a61c3226ff91454fadf2f9360b4277f2a1c1 Mon Sep 17 00:00:00 2001 From: jperras Date: Mon, 10 Aug 2009 19:47:41 -0400 Subject: [PATCH 02/19] Unifying case for single-letter interactive shell input, most notably SchemaShell, which previously failed on uppercase interactive input. --- cake/console/libs/api.php | 2 +- cake/console/libs/i18n.php | 10 +++++----- cake/console/libs/schema.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cake/console/libs/api.php b/cake/console/libs/api.php index fb529e439..87aefc10a 100644 --- a/cake/console/libs/api.php +++ b/cake/console/libs/api.php @@ -117,7 +117,7 @@ class ApiShell extends Shell { $this->out($list); $methods = array_keys($parsed); - while ($number = $this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.', true), null, 'q')) { + while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.', true), null, 'q'))) { if ($number === 'q') { $this->out(__('Done', true)); $this->_stop(); diff --git a/cake/console/libs/i18n.php b/cake/console/libs/i18n.php index aa5fe8b8a..f0e23b91b 100644 --- a/cake/console/libs/i18n.php +++ b/cake/console/libs/i18n.php @@ -76,18 +76,18 @@ class I18nShell extends Shell { $this->out(__('[H]elp', true)); $this->out(__('[Q]uit', true)); - $choice = strtoupper($this->in(__('What would you like to do?', true), array('E', 'I', 'H', 'Q'))); + $choice = strtolower($this->in(__('What would you like to do?', true), array('E', 'I', 'H', 'Q'))); switch ($choice) { - case 'E': + case 'e': $this->Extract->execute(); break; - case 'I': + case 'i': $this->initdb(); break; - case 'H': + case 'h': $this->help(); break; - case 'Q': + case 'q': exit(0); break; default: diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index c04a399cb..62ceded53 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -129,7 +129,7 @@ class SchemaShell extends Shell { if (!$snapshot && file_exists($this->Schema->path . DS . $this->params['file'])) { $snapshot = true; - $result = $this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's'); + $result = strtolower($this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's')); if ($result === 'q') { $this->_stop(); } @@ -426,4 +426,4 @@ class SchemaShell extends Shell { $this->_stop(); } } -?> +?> \ No newline at end of file From 417bdb4514256fe925461fe96270beb906d0e633 Mon Sep 17 00:00:00 2001 From: burzum Date: Wed, 12 Aug 2009 16:08:31 +0200 Subject: [PATCH 03/19] Fixing building of the right vendor path in the dispatcher in the case the plugin name appears again in the path --- cake/dispatcher.php | 3 +-- cake/tests/cases/dispatcher.test.php | 15 +++++++++++++++ .../test_plugin/vendors/js/test_plugin/test.js | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 cake/tests/test_app/plugins/test_plugin/vendors/js/test_plugin/test.js diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 36a139eaf..063bdf458 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -619,7 +619,7 @@ class Dispatcher extends Object { if ($pos > 0) { $plugin = substr($url, 0, $pos - 1); - $url = str_replace($plugin . '/', '', $url); + $url = preg_replace('/^' . preg_quote($plugin) . '\//i', '', $url); $pluginPaths = Configure::read('pluginPaths'); $count = count($pluginPaths); for ($i = 0; $i < $count; $i++) { @@ -627,7 +627,6 @@ class Dispatcher extends Object { } } $paths = array_merge($paths, Configure::read('vendorPaths')); - foreach ($paths as $path) { if (is_file($path . $url) && file_exists($path . $url)) { $assetFile = $path . $url; diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index fd0fff3b9..725a1467f 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -1700,6 +1700,20 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual('this is the test asset css file', $result); + ob_start(); + $Dispatcher->cached('test_plugin/js/test_plugin/test.js'); + $result = ob_get_clean(); + $this->assertEqual('alert("Test App");', $result); + + + Configure::write('debug', 0); + $Dispatcher->params = $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js'); + ob_start(); + $Dispatcher->cached('test_plugin/js/test_plugin/test.js'); + $result = ob_get_clean(); + $this->assertEqual('alert("Test App");', $result); + + Configure::write('debug', 0); $Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css'); ob_start(); @@ -1707,6 +1721,7 @@ class DispatcherTest extends CakeTestCase { $result = ob_get_clean(); $this->assertEqual('this is the test plugin asset css file', $result); + Configure::write('debug', 0); $Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif'); ob_start(); diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/js/test_plugin/test.js b/cake/tests/test_app/plugins/test_plugin/vendors/js/test_plugin/test.js new file mode 100644 index 000000000..6db1d7d02 --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/vendors/js/test_plugin/test.js @@ -0,0 +1 @@ +alert("Test App"); \ No newline at end of file From 1a86de5fe3d52e66f4cc37212efd19aa3c611e8b Mon Sep 17 00:00:00 2001 From: burzum Date: Wed, 12 Aug 2009 17:11:36 +0200 Subject: [PATCH 04/19] Correction to escape the / --- cake/dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 063bdf458..6140efacf 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -619,7 +619,7 @@ class Dispatcher extends Object { if ($pos > 0) { $plugin = substr($url, 0, $pos - 1); - $url = preg_replace('/^' . preg_quote($plugin) . '\//i', '', $url); + $url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url); $pluginPaths = Configure::read('pluginPaths'); $count = count($pluginPaths); for ($i = 0; $i < $count; $i++) { From adc198805f96e6ac41ad1017f855973be0502aab Mon Sep 17 00:00:00 2001 From: jperras Date: Thu, 13 Aug 2009 11:29:00 -0400 Subject: [PATCH 05/19] Dispatcher::parseParams() now works with file uploads that are not indexed by model. Fixes #9 --- cake/dispatcher.php | 18 ++++++++++++------ cake/tests/cases/dispatcher.test.php | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 6140efacf..ca147f305 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -303,22 +303,28 @@ class Dispatcher extends Object { $params['url'] = $url; } } + foreach ($_FILES as $name => $data) { if ($name != 'data') { $params['form'][$name] = $data; } } + if (isset($_FILES['data'])) { foreach ($_FILES['data'] as $key => $data) { foreach ($data as $model => $fields) { - foreach ($fields as $field => $value) { - if (is_array($value)) { - foreach ($value as $k => $v) { - $params['data'][$model][$field][$k][$key] = $v; + if (is_array($fields)) { + foreach ($fields as $field => $value) { + if (is_array($value)) { + foreach ($value as $k => $v) { + $params['data'][$model][$field][$k][$key] = $v; + } + } else { + $params['data'][$model][$field][$key] = $value; } - } else { - $params['data'][$model][$field][$key] = $value; } + } else { + $params['data'][$model][$key] = $fields; } } } diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index 725a1467f..613c8949a 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -883,6 +883,32 @@ class DispatcherTest extends CakeTestCase { ) ); $this->assertEqual($result['data'], $expected); + + + $_FILES = array( + 'data' => array( + 'name' => array('birth_cert' => 'born on.txt'), + 'type' => array('birth_cert' => 'application/octet-stream'), + 'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'), + 'error' => array('birth_cert' => 0), + 'size' => array('birth_cert' => 123) + ) + ); + + $Dispatcher =& new Dispatcher(); + $result = $Dispatcher->parseParams('/'); + + $expected = array( + 'birth_cert' => array( + 'name' => 'born on.txt', + 'type' => 'application/octet-stream', + 'tmp_name' => '/private/var/tmp/phpbsUWfH', + 'error' => 0, + 'size' => 123 + ) + ); + + $this->assertEqual($result['data'], $expected); } /** * testGetUrl method From 2737062c6f9d92c841dfa34b84b44b8585c51b0d Mon Sep 17 00:00:00 2001 From: jperras Date: Thu, 13 Aug 2009 13:57:15 -0400 Subject: [PATCH 06/19] Fixing doc block for TimeHelper::timeAgoInWords(). Fixes #27. --- cake/libs/view/helpers/time.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index e2a8c723a..62792d909 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -295,8 +295,8 @@ class TimeHelper extends AppHelper { * Relative dates look something like this: * 3 weeks, 4 days ago * 15 seconds ago - * Formatted dates look like this: - * on 02/18/2004 + * + * Default date formatting is d/m/yy e.g: on 18/2/09 * * The returned string includes 'ago' or 'on' and assumes you'll properly add a word * like 'Posted ' before the function output. From ab50bbe5953867d428c3be32ffa34ff0cdb1e372 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 13 Aug 2009 21:29:33 -0400 Subject: [PATCH 07/19] Cleaning up doc blocks. Removing commented out code. Removing use of a() --- cake/libs/xml.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 1a2048800..e6efe66a8 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -815,19 +815,19 @@ class Xml extends XmlNode { * Constructor. Sets up the XML parser with options, gives it this object as * its XML object, and sets some variables. * + * ### Options + * - 'root': The name of the root element, defaults to '#document' + * - 'version': The XML version, defaults to '1.0' + * - 'encoding': Document encoding, defaults to 'UTF-8' + * - 'namespaces': An array of namespaces (as strings) used in this document + * - 'format': Specifies the format this document converts to when parsed or + * rendered out as text, either 'attributes' or 'tags', defaults to 'attributes' + * - 'tags': An array specifying any tag-specific formatting options, indexed + * by tag name. See XmlNode::normalize(). * @param mixed $input The content with which this XML document should be initialized. Can be a - * string, array or object. If a string is specified, it may be a literal XML - * document, or a URL or file path to read from. - * @param array $options Options to set up with, valid options are as follows: - * - 'root': The name of the root element, defaults to '#document' - * - 'version': The XML version, defaults to '1.0' - * - 'encoding': Document encoding, defaults to 'UTF-8' - * - 'namespaces': An array of namespaces (as strings) used in this document - * - 'format': Specifies the format this document converts to when parsed or - * rendered out as text, either 'attributes' or 'tags', - * defaults to 'attributes' - * - 'tags': An array specifying any tag-specific formatting options, indexed - * by tag name. See XmlNode::normalize(). + * string, array or object. If a string is specified, it may be a literal XML + * document, or a URL or file path to read from. + * @param array $options Options to set up with, for valid options see above: * @see XmlNode::normalize() */ function __construct($input = null, $options = array()) { @@ -856,9 +856,6 @@ class Xml extends XmlNode { $Root->append($input, $options); } } - // if (Configure::read('App.encoding') !== null) { - // $this->encoding = Configure::read('App.encoding'); - // } } /** * Initialize XML object from a given XML string. Returns false on error. @@ -900,8 +897,8 @@ class Xml extends XmlNode { $this->__initParser(); $this->__rawData = trim($this->__rawData); $this->__header = trim(str_replace( - a('<' . '?', '?' . '>'), - a('', ''), + array('<' . '?', '?' . '>'), + array('', ''), substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>')) )); From 5a971ddbf04810948d36c3df5873da87766a735a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 13 Aug 2009 22:47:17 -0400 Subject: [PATCH 08/19] Fixing Xml::toArray() Where camelcased data was collapsed and corrupted. Causing unpredictable data structures with empty tags. Minor changes to existing behavior. See modified test cases. Fixes #8 --- cake/libs/xml.php | 7 ++-- cake/tests/cases/libs/xml.test.php | 56 +++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index e6efe66a8..0d91825bc 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -676,7 +676,6 @@ class XmlNode extends Object { if ($child->attributes) { $value = array_merge(array('value' => $value), $child->attributes); } - if (isset($out[$child->name]) || isset($multi[$key])) { if (!isset($multi[$key])) { $multi[$key] = array($out[$child->name]); @@ -689,15 +688,16 @@ class XmlNode extends Object { continue; } elseif (count($child->children) === 0 && $child->value == '') { $value = $child->attributes; - if (isset($out[$child->name]) || isset($multi[$key])) { if (!isset($multi[$key])) { $multi[$key] = array($out[$child->name]); unset($out[$child->name]); } $multi[$key][] = $value; - } else { + } elseif (!empty($value)) { $out[$key] = $value; + } else { + $out[$child->name] = $value; } continue; } else { @@ -909,7 +909,6 @@ class Xml extends XmlNode { for ($i = 0; $i < $count; $i++) { $data = $vals[$i]; $data += array('tag' => null, 'value' => null, 'attributes' => array()); - switch ($data['type']) { case "open" : $xml =& $xml->createElement($data['tag'], $data['value'], $data['attributes']); diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index e53a452e8..acff6c89b 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -759,6 +759,60 @@ class XmlTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * test that empty values do not casefold collapse + * + * @see http://code.cakephp.org/tickets/view/8 + * @return void + **/ + function testCaseFoldingWithEmptyValues() { + $filledValue = ' + update user information + 1 + + 1 + varchar(45) + + '; + $xml =& new XML($filledValue); + $expected = array( + 'Method' => array( + 'name' => 'set_user_settings', + 'title' => 'update user information', + 'user' => '1', + 'User' => array( + 'id' => 1, + 'name' => 'varchar(45)', + ), + ) + ); + $result = $xml->toArray(); + $this->assertEqual($result, $expected); + + $emptyValue =' + update user information + + + 1 + varchar(45) + + '; + + $xml =& new XML($emptyValue); + $expected = array( + 'Method' => array( + 'name' => 'set_user_settings', + 'title' => 'update user information', + 'user' => array(), + 'User' => array( + 'id' => 1, + 'name' => 'varchar(45)', + ), + ) + ); + $result = $xml->toArray(); + $this->assertEqual($result, $expected); + } /** * testMixedParsing method * @@ -921,7 +975,7 @@ class XmlTest extends CakeTestCase { 'Example' => array( 'Item' => array( 'title' => 'An example of a correctly reversed XMLNode', - 'Desc' => array(), + 'desc' => array(), ) ) ); From cca3281f8c9a543e8f7554a679004d351ac2d79d Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 19 Aug 2009 13:03:36 -0400 Subject: [PATCH 09/19] Fixing complex expression handling in DboSource::fields(). Making AS a variable controlled by implementing dbo. Test cases added. Fixes #38 --- cake/libs/model/datasources/dbo_source.php | 21 +++++++++++-------- .../model/datasources/dbo_source.test.php | 6 +++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 8a4d9b2bc..741f1bfd4 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -78,8 +78,8 @@ class DboSource extends DataSource { * @access protected */ var $_commands = array( - 'begin' => 'BEGIN', - 'commit' => 'COMMIT', + 'begin' => 'BEGIN', + 'commit' => 'COMMIT', 'rollback' => 'ROLLBACK' ); /** @@ -409,14 +409,15 @@ class DboSource extends DataSource { $data[$i] = str_replace($this->startQuote . $this->startQuote, $this->startQuote, $data[$i]); $data[$i] = str_replace($this->startQuote . '(', '(', $data[$i]); $data[$i] = str_replace(')' . $this->startQuote, ')', $data[$i]); + $alias = !empty($this->alias) ? $this->alias : 'AS '; - if (preg_match('/\s+AS\s+/', $data[$i])) { - if (preg_match('/\w+\s+AS\s+/', $data[$i])) { - $quoted = $this->endQuote . ' AS ' . $this->startQuote; - $data[$i] = str_replace(' AS ', $quoted, $data[$i]); + if (preg_match('/\s+' . $alias . '\s*/', $data[$i])) { + if (preg_match('/\w+\s+' . $alias . '\s*/', $data[$i])) { + $quoted = $this->endQuote . ' ' . $alias . $this->startQuote; + $data[$i] = str_replace(' ' . $alias, $quoted, $data[$i]); } else { - $quoted = ' AS ' . $this->startQuote; - $data[$i] = str_replace(' AS ', $quoted, $data[$i]) . $this->endQuote; + $quoted = $alias . $this->startQuote; + $data[$i] = str_replace($alias, $quoted, $data[$i]) . $this->endQuote; } } @@ -1680,7 +1681,9 @@ class DboSource extends DataSource { if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) { for ($i = 0; $i < $count; $i++) { - if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) { + if (preg_match('/^\(.*\)\s' . $this->alias . '.*/i', $fields[$i])){ + continue; + } elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) { $prepend = ''; if (strpos($fields[$i], 'DISTINCT') !== false) { 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 87c5cfcee..4da90c9be 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2696,6 +2696,10 @@ class DboSourceTest extends CakeTestCase { ); $this->assertEqual($result, $expected); + $result = $this->testDb->fields($this->Model, null, "(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`"); + $expected = array("(`Provider`.`star_total` / `Provider`.`total_ratings`) as `rating`"); + $this->assertEqual($result, $expected); + $result = $this->testDb->fields($this->Model, 'Post'); $expected = array( '`Post`.`id`', '`Post`.`client_id`', '`Post`.`name`', '`Post`.`login`', @@ -2773,7 +2777,7 @@ class DboSourceTest extends CakeTestCase { $expected = array( '`Foo`.`id`', '`Foo`.`title`', - '(user_count + discussion_count + post_count) AS `score`' + '(user_count + discussion_count + post_count) AS score' ); $this->assertEqual($result, $expected); } From 3f0f4b901d08b7a0f04fd0f93d7b2fdf3ab9630d Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 21 Aug 2009 12:52:46 -0400 Subject: [PATCH 10/19] Changing line endings to LF --- .../fixtures/counter_cache_post_fixture.php | 98 +++++++++---------- .../fixtures/counter_cache_user_fixture.php | 96 +++++++++--------- 2 files changed, 97 insertions(+), 97 deletions(-) diff --git a/cake/tests/fixtures/counter_cache_post_fixture.php b/cake/tests/fixtures/counter_cache_post_fixture.php index eb9413072..4f696eb3a 100644 --- a/cake/tests/fixtures/counter_cache_post_fixture.php +++ b/cake/tests/fixtures/counter_cache_post_fixture.php @@ -1,50 +1,50 @@ - - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) - * - * Licensed under The Open Group Test Suite License - * Redistributions of files must retain the above copyright notice. - * - * @filesource - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) - * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.fixtures - * @since CakePHP(tm) v 1.2.0.4667 - * @version $Revision: 7848 $ - * @modifiedby $LastChangedBy: renan.saddam $ - * @lastmodified $Date: 2008-11-07 21:58:37 -0500 (Fri, 07 Nov 2008) $ - * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License - */ -/** - * Short description for class. - * - * @package cake - * @subpackage cake.tests.fixtures - */ -class CounterCachePostFixture extends CakeTestFixture { - - var $name = 'CounterCachePost'; - - var $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'title' => array('type' => 'string', 'length' => 255, 'null' => false), - 'user_id' => array('type' => 'integer', 'null' => true), - ); - - var $records = array( - array('id' => 1, 'title' => 'Rock and Roll', 'user_id' => 66), - array('id' => 2, 'title' => 'Music', 'user_id' => 66), - array('id' => 3, 'title' => 'Food', 'user_id' => 301), - ); -} - + + * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.tests.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision: 7848 $ + * @modifiedby $LastChangedBy: renan.saddam $ + * @lastmodified $Date: 2008-11-07 21:58:37 -0500 (Fri, 07 Nov 2008) $ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake + * @subpackage cake.tests.fixtures + */ +class CounterCachePostFixture extends CakeTestFixture { + + var $name = 'CounterCachePost'; + + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'title' => array('type' => 'string', 'length' => 255, 'null' => false), + 'user_id' => array('type' => 'integer', 'null' => true), + ); + + var $records = array( + array('id' => 1, 'title' => 'Rock and Roll', 'user_id' => 66), + array('id' => 2, 'title' => 'Music', 'user_id' => 66), + array('id' => 3, 'title' => 'Food', 'user_id' => 301), + ); +} + ?> \ No newline at end of file diff --git a/cake/tests/fixtures/counter_cache_user_fixture.php b/cake/tests/fixtures/counter_cache_user_fixture.php index ad592386a..4739dab0a 100644 --- a/cake/tests/fixtures/counter_cache_user_fixture.php +++ b/cake/tests/fixtures/counter_cache_user_fixture.php @@ -1,49 +1,49 @@ - - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) - * - * Licensed under The Open Group Test Suite License - * Redistributions of files must retain the above copyright notice. - * - * @filesource - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) - * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.fixtures - * @since CakePHP(tm) v 1.2.0.4667 - * @version $Revision: 7848 $ - * @modifiedby $LastChangedBy: renan.saddam $ - * @lastmodified $Date: 2008-11-07 21:58:37 -0500 (Fri, 07 Nov 2008) $ - * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License - */ -/** - * Short description for class. - * - * @package cake - * @subpackage cake.tests.fixtures - */ -class CounterCacheUserFixture extends CakeTestFixture { - - var $name = 'CounterCacheUser'; - - var $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'name' => array('type' => 'string', 'length' => 255, 'null' => false), - 'post_count' => array('type' => 'integer', 'null' => true) - ); - - var $records = array( - array('id' => 66, 'name' => 'Alexander','post_count' => 2), - array('id' => 301, 'name' => 'Steven','post_count' => 1), - ); -} - + + * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.tests.fixtures + * @since CakePHP(tm) v 1.2.0.4667 + * @version $Revision: 7848 $ + * @modifiedby $LastChangedBy: renan.saddam $ + * @lastmodified $Date: 2008-11-07 21:58:37 -0500 (Fri, 07 Nov 2008) $ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * Short description for class. + * + * @package cake + * @subpackage cake.tests.fixtures + */ +class CounterCacheUserFixture extends CakeTestFixture { + + var $name = 'CounterCacheUser'; + + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'name' => array('type' => 'string', 'length' => 255, 'null' => false), + 'post_count' => array('type' => 'integer', 'null' => true) + ); + + var $records = array( + array('id' => 66, 'name' => 'Alexander','post_count' => 2), + array('id' => 301, 'name' => 'Steven','post_count' => 1), + ); +} + ?> \ No newline at end of file From 98ad480bf2408530a845d1985a32348c626618b2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 21 Aug 2009 22:33:33 -0400 Subject: [PATCH 11/19] Fixing error string passing in SchemaShell::__run() Fixes #45 --- cake/console/libs/schema.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 62ceded53..4375a6626 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -369,8 +369,7 @@ class SchemaShell extends Shell { Configure::write('debug', 2); $db =& ConnectionManager::getDataSource($this->Schema->connection); $db->fullDebug = true; - - $errors = array(); + foreach ($contents as $table => $sql) { if (empty($sql)) { $this->out(sprintf(__('%s is up to date.', true), $table)); @@ -382,15 +381,16 @@ class SchemaShell extends Shell { if (!$Schema->before(array($event => $table))) { return false; } - if (!$db->_execute($sql)) { + $error = null; + if (!$db->execute($sql)) { $error = $table . ': ' . $db->lastError(); } - $Schema->after(array($event => $table, 'errors'=> $errors)); + $Schema->after(array($event => $table, 'errors' => $error)); - if (isset($error)) { + if (!empty($error)) { $this->out($error); - } elseif ($this->__dry !== true) { + } else { $this->out(sprintf(__('%s updated.', true), $table)); } } From 47d91813136f7dc8fe651fd9a2d5f63d21f19cb7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 21 Aug 2009 23:18:27 -0400 Subject: [PATCH 12/19] Adding test case from 'mradosta'. Fixing issue with non-zero indexed arrays and Set::extract() Fixes #6 --- cake/libs/set.php | 5 ++++- cake/tests/cases/libs/set.test.php | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index d48adc7de..5e80f46b2 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -386,7 +386,10 @@ class Set extends Object { $contexts = $data; $options = array_merge(array('flatten' => true), $options); if (!isset($contexts[0])) { - $contexts = array($data); + $current = current($data); + if ((is_array($current) && count($data) <= 1) || !is_array($current)) { + $contexts = array($data); + } } $tokens = array_slice(preg_split('/(?assertEqual($r, $expected); + $nonZero = array( + 1 => array( + 'User' => array( + 'id' => 1, + 'name' => 'John', + ) + ), + 2 => array( + 'User' => array( + 'id' => 2, + 'name' => 'Bob', + ) + ), + 3 => array( + 'User' => array( + 'id' => 3, + 'name' => 'Tony', + ) + ) + ); + $expected = array(1, 2, 3); + $r = Set::extract('/User/id', $nonZero); + $this->assertEqual($r, $expected); + $common = array( array( 'Article' => array( @@ -969,7 +993,6 @@ class SetTest extends CakeTestCase { $expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647')); $r = Set::extract('/file/.[type=application/zip]', $f); $this->assertEqual($r, $expected); - } /** * testMatches method @@ -2396,7 +2419,7 @@ class SetTest extends CakeTestCase { array( 'Item' => array( 'title' => 'An example of a correctly reversed XMLNode', - 'Desc' => array(), + 'desc' => array(), ) ) ); From 6f8f4c5a05b7fa26844c77f8f67c1fbd31e33c25 Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 22 Aug 2009 20:26:27 -0400 Subject: [PATCH 13/19] Adding waves -> wave as irregular singularization rule. Fixes #47. --- cake/libs/inflector.php | 7 +++++-- cake/tests/cases/libs/inflector.test.php | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 91c7e98ab..71f07b4e3 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -318,7 +318,8 @@ class Inflector extends Object { 'nexus', 'Niasese', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', - 'whiting', 'wildebeest', 'Yengeese'); + 'whiting', 'wildebeest', 'Yengeese' + ); $coreIrregularSingular = array( 'atlases' => 'atlas', @@ -349,7 +350,9 @@ class Inflector extends Object { 'soliloquies' => 'soliloquy', 'testes' => 'testis', 'trilbys' => 'trilby', - 'turfs' => 'turf'); + 'turfs' => 'turf', + 'waves' => 'wave' + ); $singularRules = Set::pushDiff($this->__singularRules, $coreSingularRules); $uninflected = Set::pushDiff($this->__uninflectedSingular, $coreUninflectedSingular); diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 9aa007187..2c293bb53 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -108,6 +108,7 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::singularize('taxes'), 'tax'); $this->assertEqual(Inflector::singularize('faxes'), 'fax'); $this->assertEqual(Inflector::singularize('waxes'), 'wax'); + $this->assertEqual(Inflector::singularize('waves'), 'wave'); $this->assertEqual(Inflector::singularize(''), ''); } /** @@ -151,6 +152,7 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::pluralize('people'), 'people'); $this->assertEqual(Inflector::pluralize('glove'), 'gloves'); $this->assertEqual(Inflector::pluralize('crisis'), 'crises'); + $this->assertEqual(Inflector::pluralize('wave'), 'waves'); $this->assertEqual(Inflector::pluralize(''), ''); } /** From e9cfb6642425cdbb8cdefb161cc8c32039958c64 Mon Sep 17 00:00:00 2001 From: jperras Date: Sun, 23 Aug 2009 17:52:40 -0400 Subject: [PATCH 14/19] Fixing calling of method from incorrect object in DboOracle::describe(). Fixes #21. --- cake/libs/model/datasources/dbo/dbo_oracle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo/dbo_oracle.php b/cake/libs/model/datasources/dbo/dbo_oracle.php index 1b87ec1a5..4aa25a6a5 100644 --- a/cake/libs/model/datasources/dbo/dbo_oracle.php +++ b/cake/libs/model/datasources/dbo/dbo_oracle.php @@ -465,7 +465,7 @@ class DboOracle extends DboSource { * @access public */ function describe(&$model) { - $table = $model->fullTableName($model, false); + $table = $this->fullTableName($model, false); if (!empty($model->sequence)) { $this->_sequenceMap[$table] = $model->sequence; From 31ec714e2eb322ecfcc45fa4a2aeb2cfa1f479d8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 23 Aug 2009 23:13:56 -0400 Subject: [PATCH 15/19] Adding View::_paths() optimization. Test cases added. Refs #49 --- cake/libs/view/view.php | 5 ++- cake/tests/cases/libs/view/view.test.php | 47 +++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 1604debfb..96aac913e 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -895,11 +895,14 @@ class View extends Object { } $paths = array(); $viewPaths = Configure::read('viewPaths'); + $corePaths = array_flip(Configure::corePaths('view')); if (!empty($plugin)) { $count = count($viewPaths); for ($i = 0; $i < $count; $i++) { - $paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS; + if (!isset($corePaths[$viewPaths[$i]])) { + $paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS; + } } $pluginPaths = Configure::read('pluginPaths'); $count = count($pluginPaths); diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 50dbc4260..103a4b736 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -143,6 +143,18 @@ class TestView extends View { function loadHelpers(&$loaded, $helpers, $parent = null) { return $this->_loadHelpers($loaded, $helpers, $parent); } +/** + * paths method + * + * @param string $plugin + * @param boolean $cached + * @access public + * @return void + */ + function paths($plugin = null, $cached = true) { + return $this->_paths($plugin, $cached); + } + /** * cakeError method * @@ -237,7 +249,10 @@ class ViewTest extends CakeTestCase { $View = new TestView($this->Controller); Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)); - Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); + Configure::write('viewPaths', array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS, + )); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'tests' . DS .'index.ctp'; $result = $View->getViewFileName('index'); @@ -247,6 +262,36 @@ class ViewTest extends CakeTestCase { $result = $View->getLayoutFileName(); $this->assertEqual($result, $expected); } +/** + * test that plugin/$plugin_name is only appended to the paths it should be. + * + * @return void + **/ + function testPluginPathGeneration() { + $this->Controller->plugin = 'test_plugin'; + $this->Controller->name = 'TestPlugin'; + $this->Controller->viewPath = 'tests'; + $this->Controller->action = 'index'; + + Configure::write('viewPaths', array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS, + )); + + $View = new TestView($this->Controller); + $paths = $View->paths(); + $this->assertEqual($paths, Configure::read('viewPaths')); + + $paths = $View->paths('test_plugin'); + $expected = array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'plugins' . DS . 'test_plugin' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'views' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS + ); + $this->assertEqual($paths, $expected); + } + /** * test that CamelCase plugins still find their view files. * From 2dca77cbcbd738217d76128dcdc3cd9a3697dcea Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 25 Aug 2009 23:34:19 -0400 Subject: [PATCH 16/19] Updating Scaffold to merge hasAndBelongsToMany keys when generating field lists for scaffolded forms. Fixes #48 --- cake/libs/controller/scaffold.php | 4 ++ .../cases/libs/controller/scaffold.test.php | 66 ++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 84549c938..186bf0998 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -237,6 +237,10 @@ class Scaffold extends Object { * @access private */ function __scaffoldForm($action = 'edit') { + $this->controller->viewVars['scaffoldFields'] = array_merge( + $this->controller->viewVars['scaffoldFields'], + array_keys($this->ScaffoldModel->hasAndBelongsToMany) + ); $this->controller->render($action, $this->layout); $this->_output(); } diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index d7dfa7ea3..64aad9c07 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -140,6 +140,19 @@ class ScaffoldMock extends CakeTestModel { 'foreignKey' => 'article_id', ) ); +/** + * hasAndBelongsToMany property + * + * @var string + **/ + var $hasAndBelongsToMany = array( + 'ScaffoldTag' => array( + 'className' => 'ScaffoldTag', + 'foreignKey' => 'post_id', + 'associationForeignKey' => 'tag_id', + 'joinTable' => 'posts_tags' + ) + ); } /** * ScaffoldUser class @@ -195,6 +208,21 @@ class ScaffoldComment extends CakeTestModel { ) ); } +/** + * ScaffoldTag class + * + * @package cake + * @subpackage cake.tests.cases.libs.controller + */ +class ScaffoldTag extends CakeTestModel { +/** + * useTable property + * + * @var string 'posts' + * @access public + */ + var $useTable = 'tags'; +} /** * TestScaffoldView class * @@ -226,7 +254,7 @@ class ScaffoldViewTest extends CakeTestCase { * @var array * @access public */ - var $fixtures = array('core.article', 'core.user', 'core.comment'); + var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.posts_tag', 'core.tag'); /** * startTest method * @@ -559,7 +587,7 @@ class ScaffoldTest extends CakeTestCase { * @var array * @access public */ - var $fixtures = array('core.article', 'core.user', 'core.comment'); + var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.posts_tag', 'core.tag'); /** * startTest method * @@ -648,6 +676,40 @@ class ScaffoldTest extends CakeTestCase { $this->assertEqual($result['pluralVar'], 'scaffoldMock'); $this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated')); } +/** + * test that habtm relationship keys get added to scaffoldFields. + * + * @see http://code.cakephp.org/tickets/view/48 + * @return void + **/ + function testHabtmFieldAdditionWithScaffoldForm() { + $this->Controller->action = 'edit'; + $this->Controller->here = '/scaffold_mock'; + $this->Controller->webroot = '/'; + $params = array( + 'plugin' => null, + 'pass' => array(1), + 'form' => array(), + 'named' => array(), + 'url' => array('url' =>'scaffold_mock'), + 'controller' => 'scaffold_mock', + 'action' => 'edit', + ); + //set router. + Router::reload(); + Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/'))); + $this->Controller->params = $params; + $this->Controller->controller = 'scaffold_mock'; + $this->Controller->base = '/'; + $this->Controller->constructClasses(); + ob_start(); + $Scaffold = new Scaffold($this->Controller, $params); + $result = ob_get_clean(); + $this->assertPattern('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result); + + $result = $Scaffold->controller->viewVars; + $this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated', 'ScaffoldTag')); + } /** * test that the proper names and variable values are set by Scaffold * From 8be5de947bb75ea71d9685708ec7c73727be72f1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 Aug 2009 19:07:36 -0400 Subject: [PATCH 17/19] Minor refactor in how paths are checked, so that fallback extensions are checked only when all paths fail, instead of for each path. Refs #49 --- cake/libs/view/view.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 96aac913e..1ed8c01cb 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -805,14 +805,13 @@ class View extends Object { } $paths = $this->_paths(Inflector::underscore($this->plugin)); - - foreach ($paths as $path) { - if (file_exists($path . $name . $this->ext)) { - return $path . $name . $this->ext; - } elseif (file_exists($path . $name . '.ctp')) { - return $path . $name . '.ctp'; - } elseif (file_exists($path . $name . '.thtml')) { - return $path . $name . '.thtml'; + + $exts = array($this->ext, '.ctp', '.thtml'); + foreach ($exts as $ext) { + foreach ($paths as $path) { + if (file_exists($path . $name . $ext)) { + return $path . $name . $ext; + } } } $defaultPath = $paths[0]; @@ -848,8 +847,8 @@ class View extends Object { $file = 'layouts' . DS . $subDir . $name; $exts = array($this->ext, '.ctp', '.thtml'); - foreach ($paths as $path) { - foreach ($exts as $ext) { + foreach ($exts as $ext) { + foreach ($paths as $path) { if (file_exists($path . $file . $ext)) { return $path . $file . $ext; } From c0ba43c884592202930f0b60b17d335ff35cdf66 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 31 Aug 2009 13:38:40 -0400 Subject: [PATCH 18/19] Fixing non output of flash messages from Scaffolds when controller is not using Sessions. Refs #64 --- cake/libs/controller/scaffold.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 186bf0998..8b62e2242 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -287,7 +287,8 @@ class Scaffold extends Object { $this->controller->Session->setFlash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success)); $this->controller->redirect($this->redirect); } else { - return $this->controller->flash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success), $this->redirect); + $this->controller->flash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success), $this->redirect); + return $this->_output(); } } else { return $this->controller->_afterScaffoldSaveError($action); @@ -336,8 +337,8 @@ class Scaffold extends Object { $this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey))); $this->controller->redirect($this->redirect); } else { - return $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)), - '/' . Inflector::underscore($this->controller->viewPath)); + $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)), '/' . Inflector::underscore($this->controller->viewPath)); + return $this->_output(); } if ($this->ScaffoldModel->del($id)) { @@ -345,14 +346,16 @@ class Scaffold extends Object { $this->controller->Session->setFlash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id)); $this->controller->redirect($this->redirect); } else { - return $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath); + $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath); + return $this->_output(); } } else { if (isset($this->controller->Session) && $this->controller->Session->valid() != false) { $this->controller->Session->setFlash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id)); $this->controller->redirect($this->redirect); } else { - return $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath); + $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath); + return $this->_output(); } } } elseif ($this->controller->_scaffoldError('delete') === false) { From a678a603c0fd1a6307211aa4cad779e55c5efaef Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 31 Aug 2009 13:48:32 -0400 Subject: [PATCH 19/19] Simplifying message generation. Fixing inflection of model names. Adding tests for flash page generation. Refs #64 --- cake/libs/controller/scaffold.php | 13 +++++-- .../cases/libs/controller/scaffold.test.php | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 8b62e2242..165e2b562 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -267,11 +267,12 @@ class Scaffold extends Object { } if (!$this->ScaffoldModel->exists()) { + $message = sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)); if (isset($this->controller->Session) && $this->controller->Session->valid() != false) { - $this->controller->Session->setFlash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey))); + $this->controller->Session->setFlash($message); $this->controller->redirect($this->redirect); } else { - return $this->controller->flash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)), $this->redirect); + return $this->controller->flash($message, $this->redirect); } } } @@ -283,11 +284,15 @@ class Scaffold extends Object { if ($this->ScaffoldModel->save($this->controller->data)) { if ($this->controller->_afterScaffoldSave($action)) { + $message = sprintf(__('The %1$s has been %2$s', true), + Inflector::humanize($this->modelKey), + $success + ); if (isset($this->controller->Session) && $this->controller->Session->valid() != false) { - $this->controller->Session->setFlash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success)); + $this->controller->Session->setFlash($message); $this->controller->redirect($this->redirect); } else { - $this->controller->flash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success), $this->redirect); + $this->controller->flash($message, $this->redirect); return $this->_output(); } } else { diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 64aad9c07..72cab3eb9 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -676,6 +676,45 @@ class ScaffoldTest extends CakeTestCase { $this->assertEqual($result['pluralVar'], 'scaffoldMock'); $this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated')); } +/** + * test that scaffold outputs flash messages when sessions are unset. + * + * @return void + **/ + function testScaffoldFlashMessages() { + $this->Controller->action = 'edit'; + $this->Controller->here = '/scaffold_mock'; + $this->Controller->webroot = '/'; + $params = array( + 'plugin' => null, + 'pass' => array(1), + 'form' => array(), + 'named' => array(), + 'url' => array('url' =>'scaffold_mock'), + 'controller' => 'scaffold_mock', + 'action' => 'edit', + ); + //set router. + Router::reload(); + Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/'))); + $this->Controller->params = $params; + $this->Controller->controller = 'scaffold_mock'; + $this->Controller->base = '/'; + $this->Controller->data = array( + 'ScaffoldMock' => array( + 'id' => 1, + 'title' => 'New title', + 'body' => 'new body' + ) + ); + $this->Controller->constructClasses(); + unset($this->Controller->Session); + + ob_start(); + new Scaffold($this->Controller, $params); + $result = ob_get_clean(); + $this->assertPattern('/Scaffold Mock has been updated/', $result); + } /** * test that habtm relationship keys get added to scaffoldFields. *