From a4f138813bce6dc7326f6d2274fe6f8c84ec584b Mon Sep 17 00:00:00 2001 From: Raffaele Date: Fri, 3 Jan 2014 15:46:09 +0100 Subject: [PATCH 01/14] Return value if value are 0 Save correctly if the value is 0, but after the find is returned as an empty string. --- lib/Cake/Model/Behavior/TranslateBehavior.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 4adfced39ce..7195224ac12 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -305,7 +305,9 @@ public function afterFind(Model $Model, $results, $primary = false) { } } else { $value = ''; - if (!empty($row[$Model->alias][$aliasVirtual])) { + if (is_numeric($row[$Model->alias][$aliasVirtual])) { + $value = $row[$Model->alias][$aliasVirtual]; + } elseif (!empty($row[$Model->alias][$aliasVirtual])) { $value = $row[$Model->alias][$aliasVirtual]; } $row[$Model->alias][$aliasField] = $value; From 1201887ad1e31aef01529bbb5dc3b056186015c0 Mon Sep 17 00:00:00 2001 From: euromark Date: Mon, 6 Jan 2014 20:42:17 +0100 Subject: [PATCH 02/14] Clearer error message --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 546092e4a86..8e5f66cb732 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -265,6 +265,7 @@ public function drop($db) { * * @param DboSource $db An instance of the database into which the records will be inserted * @return boolean on success or if there are no records to insert, or false on failure + * @throws CakeException if count of values and fields does not match. */ public function insert($db) { if (!isset($this->_insert)) { @@ -277,10 +278,15 @@ public function insert($db) { $fields = array_unique($fields); $default = array_fill_keys($fields, null); foreach ($this->records as $record) { - $values[] = array_values(array_merge($default, $record)); + $merge = array_values(array_merge($default, $record)); + if (count($fields) !== count($merge)) { + throw new CakeException('Fixure invalid: Count of fields does not match count of values'); + } + $values[] = $merge; } $nested = $db->useNestedTransactions; $db->useNestedTransactions = false; + $result = $db->insertMulti($this->table, $fields, $values); if ( $this->primaryKey && From 865ca7acd6a4f1fc1787d62472139ff1a1650c92 Mon Sep 17 00:00:00 2001 From: euromark Date: Mon, 6 Jan 2014 20:43:30 +0100 Subject: [PATCH 03/14] wording --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 8e5f66cb732..04aaa44840a 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -265,7 +265,7 @@ public function drop($db) { * * @param DboSource $db An instance of the database into which the records will be inserted * @return boolean on success or if there are no records to insert, or false on failure - * @throws CakeException if count of values and fields does not match. + * @throws CakeException if counts of values and fields do not match. */ public function insert($db) { if (!isset($this->_insert)) { @@ -286,7 +286,6 @@ public function insert($db) { } $nested = $db->useNestedTransactions; $db->useNestedTransactions = false; - $result = $db->insertMulti($this->table, $fields, $values); if ( $this->primaryKey && From ecfd64c082321de94822184ea07b7944fadbf2a8 Mon Sep 17 00:00:00 2001 From: euromark Date: Mon, 6 Jan 2014 21:07:00 +0100 Subject: [PATCH 04/14] adding test --- .../Case/TestSuite/CakeTestFixtureTest.php | 57 ++++++++++++++++++- .../TestSuite/Fixture/CakeTestFixture.php | 2 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php index 4c791a5d52a..3488d6a926e 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php @@ -65,7 +65,7 @@ class CakeTestFixtureTestFixture extends CakeTestFixture { } /** - * StringFieldsTestFixture class + * StringTestFixture class * * @package Cake.Test.Case.TestSuite */ @@ -109,6 +109,50 @@ class StringsTestFixture extends CakeTestFixture { ); } +/** + * InvalidTestFixture class + * + * @package Cake.Test.Case.TestSuite + */ +class InvalidTestFixture extends CakeTestFixture { + +/** + * Name property + * + * @var string + */ + public $name = 'Invalid'; + +/** + * Table property + * + * @var string + */ + public $table = 'invalid'; + +/** + * Fields array - missing "email" row + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'name' => array('type' => 'string', 'length' => '255'), + 'age' => array('type' => 'integer', 'default' => 10) + ); + +/** + * Records property + * + * @var array + */ + public $records = array( + array('name' => 'Mark Doe', 'email' => 'mark.doe@email.com'), + array('name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20), + array('email' => 'jane.doe@email.com', 'name' => 'Jane Doe', 'age' => 30) + ); +} + /** * CakeTestFixtureImportFixture class * @@ -482,6 +526,17 @@ public function testInsertStrings() { $this->assertEquals($expected, $this->insertMulti['fields_values']); } +/** + * test the insert method with invalid fixture + * + * @expectedException CakeException + * @return void + */ + public function testInsertInvalid() { + $Fixture = new InvalidTestFixture(); + $return = $Fixture->insert($this->criticDb); + } + /** * Test the drop method * diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 04aaa44840a..4fd0451438f 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -280,7 +280,7 @@ public function insert($db) { foreach ($this->records as $record) { $merge = array_values(array_merge($default, $record)); if (count($fields) !== count($merge)) { - throw new CakeException('Fixure invalid: Count of fields does not match count of values'); + throw new CakeException('Fixture invalid: Count of fields does not match count of values'); } $values[] = $merge; } From 3763350667f3175296bf1c69bbdb63e7290d32ec Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 6 Jan 2014 21:21:13 -0500 Subject: [PATCH 05/14] Add test for issue #2595 Fold conditions that did the same thing and add a test case. Closes #2595 --- lib/Cake/Model/Behavior/TranslateBehavior.php | 4 +-- .../Model/Behavior/TranslateBehaviorTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 7195224ac12..9eceb725a04 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -305,9 +305,7 @@ public function afterFind(Model $Model, $results, $primary = false) { } } else { $value = ''; - if (is_numeric($row[$Model->alias][$aliasVirtual])) { - $value = $row[$Model->alias][$aliasVirtual]; - } elseif (!empty($row[$Model->alias][$aliasVirtual])) { + if (is_numeric($row[$Model->alias][$aliasVirtual]) || !empty($row[$Model->alias][$aliasVirtual])) { $value = $row[$Model->alias][$aliasVirtual]; } $row[$Model->alias][$aliasField] = $value; diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index fe18575b816..db5a659406c 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -354,6 +354,31 @@ public function testLocaleSingleAssociations() { $this->assertEquals($expected, $result); } +/** + * Test loading fields with 0 as the translated value. + */ + public function testFetchTranslationsWithZero() { + $this->loadFixtures('Translate', 'TranslatedItem'); + + $model = new TranslatedItem(); + $translateModel = $model->translateModel(); + $translateModel->updateAll(array('content' => '"0"')); + $model->locale = 'eng'; + + $result = $model->read(null, 1); + $expected = array( + 'TranslatedItem' => array( + 'id' => 1, + 'slug' => 'first_translated', + 'locale' => 'eng', + 'title' => '0', + 'content' => '0', + 'translated_article_id' => 1, + ) + ); + $this->assertEquals($expected, $result); + } + /** * testLocaleMultiple method * From caf350c01f1ca6083d54ec1f8c5a5271b1a48b25 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 7 Jan 2014 10:06:50 -0500 Subject: [PATCH 06/14] Exclude lib/Cake/Test when building pear packages. The core tests include a number of files that cause grief when the cakephp pear package is installed via composer. Excluding the core tests solves all of these problems and makes a smaller package which is nice. Fixes #2620 --- build.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/build.xml b/build.xml index af2a1e2882a..d36dbb3818d 100644 --- a/build.xml +++ b/build.xml @@ -29,6 +29,7 @@ + @@ -140,7 +137,6 @@ script - php php php php @@ -244,11 +240,11 @@ - + - + From d41bb0b1b3497080f6e4498130711e223ad45e52 Mon Sep 17 00:00:00 2001 From: pummra Date: Wed, 8 Jan 2014 09:52:05 +0000 Subject: [PATCH 07/14] Update ControllerTask.php Added an output message if no controllers are baked using the all() function. --- lib/Cake/Console/Command/Task/ControllerTask.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index e788e3b7ff4..1a8f895589c 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -110,6 +110,7 @@ public function all() { $admin = $this->Project->getPrefix(); } + $controllersCreated = 0; foreach ($this->__tables as $table) { $model = $this->_modelName($table); $controller = $this->_controllerName($model); @@ -123,8 +124,13 @@ public function all() { if ($this->bake($controller, $actions) && $unitTestExists) { $this->bakeTest($controller); } + $controllersCreated++; } } + + if ($controllersCreated === 0) { + $this->out(__d('cake_console', 'No Controllers were baked, Models need to exisit before Controllers can be baked.', $admin)); + } } /** From 0214ac403e993cb02878410a1780b16bdd04b927 Mon Sep 17 00:00:00 2001 From: pummra Date: Wed, 8 Jan 2014 10:10:40 +0000 Subject: [PATCH 08/14] Update ControllerTask.php Updated if statement for clarity and also fixed spelling mistake. --- lib/Cake/Console/Command/Task/ControllerTask.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 1a8f895589c..db7bb38e884 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -128,8 +128,8 @@ public function all() { } } - if ($controllersCreated === 0) { - $this->out(__d('cake_console', 'No Controllers were baked, Models need to exisit before Controllers can be baked.', $admin)); + if (!$controllersCreated) { + $this->out(__d('cake_console', 'No Controllers were baked, Models need to exist before Controllers can be baked.', $admin)); } } From a981c7fa8c426bc1b4e99faa6b3f13d720bee6e9 Mon Sep 17 00:00:00 2001 From: pummra Date: Wed, 8 Jan 2014 10:16:06 +0000 Subject: [PATCH 09/14] Removed trailing whitespace. --- lib/Cake/Console/Command/Task/ControllerTask.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index db7bb38e884..fa1da721980 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -127,9 +127,9 @@ public function all() { $controllersCreated++; } } - + if (!$controllersCreated) { - $this->out(__d('cake_console', 'No Controllers were baked, Models need to exist before Controllers can be baked.', $admin)); + $this->out(__d('cake_console', 'No Controllers were baked, Models need to exist before Controllers can be baked.', $admin)); } } From 5605ff48ab0649b8e662415ae553989873758bb0 Mon Sep 17 00:00:00 2001 From: pummra Date: Wed, 8 Jan 2014 12:23:03 +0000 Subject: [PATCH 10/14] Update ControllerTask.php Removed $admin from message in regards to no controllers being baked in all() function --- lib/Cake/Console/Command/Task/ControllerTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index fa1da721980..3c1079b8bab 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -129,7 +129,7 @@ public function all() { } if (!$controllersCreated) { - $this->out(__d('cake_console', 'No Controllers were baked, Models need to exist before Controllers can be baked.', $admin)); + $this->out(__d('cake_console', 'No Controllers were baked, Models need to exist before Controllers can be baked.')); } } From b20ca3f4e01a49b3f4e93505a57ec77f1502ce50 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 8 Jan 2014 09:42:13 -0500 Subject: [PATCH 11/14] Fix errors with postgres tests. --- lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index db5a659406c..44eba0881e6 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -362,7 +362,7 @@ public function testFetchTranslationsWithZero() { $model = new TranslatedItem(); $translateModel = $model->translateModel(); - $translateModel->updateAll(array('content' => '"0"')); + $translateModel->updateAll(array('content' => "'0'")); $model->locale = 'eng'; $result = $model->read(null, 1); From cd27012405f78a8953abc4a915b50c6289a3cfc9 Mon Sep 17 00:00:00 2001 From: Bryan Crowe Date: Wed, 8 Jan 2014 21:38:45 -0500 Subject: [PATCH 12/14] Simple docblock updates to CakeTime --- lib/Cake/Utility/CakeTime.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 3e4e0dcb3ad..84abf5c76cf 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -83,14 +83,14 @@ class CakeTime { public static $wordEnd = '+1 month'; /** - * Temporary variable containing timestamp value, used internally convertSpecifiers() + * Temporary variable containing the timestamp value, used internally in convertSpecifiers() * * @var integer */ protected static $_time = null; /** - * Magic set method for backward compatibility. + * Magic set method for backwards compatibility. * Used by TimeHelper to modify static variables in CakeTime * * @param string $name Variable name @@ -106,7 +106,7 @@ public function __set($name, $value) { } /** - * Magic set method for backward compatibility. + * Magic set method for backwards compatibility. * Used by TimeHelper to get static variables in CakeTime * * @param string $name Variable name From 9cc7c465d1d29f5f08713f2a52435473bf3ea1f9 Mon Sep 17 00:00:00 2001 From: Max Meiden Dasuki Date: Wed, 15 Jan 2014 15:14:00 +0800 Subject: [PATCH 13/14] fix multiple log array key definition on templates property in Debugger --- lib/Cake/Utility/Debugger.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 54f08e7f714..96482daf104 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -79,8 +79,7 @@ class Debugger { 'traceLine' => '{:reference} - {:path}, line {:line}', 'trace' => "Trace:\n{:trace}\n", 'context' => "Context:\n{:context}\n", - ), - 'log' => array(), + ) ); /** From f25e84f4fb6833f642e9db81450ff4fd85c1fca8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 15 Jan 2014 10:23:45 -0500 Subject: [PATCH 14/14] Don't select year 0 when there are all 0's. Year 0 is almost never a 'good' selection value and causes odd behavior when paired with MySQL. Fixes #2658 --- .../Test/Case/View/Helper/FormHelperTest.php | 19 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index b7bf8dd5f42..88422256ef8 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -6273,6 +6273,25 @@ public function testDateTimeWithBogusData() { $this->assertNotRegExp('/selected="selected">\d/', $result); } +/** + * testDateTime all zeros + * + * @return void + */ + public function testDateTimeAllZeros() { + $result = $this->Form->dateTime('Contact.date', + 'DMY', + false, + array( + 'empty' => array('day' => '-', 'month' => '-', 'year' => '-'), + 'value' => '0000-00-00' + ) + ); + + $this->assertRegExp('/