From 172e4bed5d262529a9376061b2043d5e1dbd4cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Tue, 21 Aug 2012 13:08:43 +0200 Subject: [PATCH 1/8] Fix STRICT warnings on PHP 5.4 --- lib/Cake/Test/test_app/Model/Datasource/Test2OtherSource.php | 4 ++-- lib/Cake/Test/test_app/Model/Datasource/Test2Source.php | 4 ++-- .../Plugin/TestPlugin/Model/Datasource/TestOtherSource.php | 4 ++-- .../Plugin/TestPlugin/Model/Datasource/TestSource.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Test/test_app/Model/Datasource/Test2OtherSource.php b/lib/Cake/Test/test_app/Model/Datasource/Test2OtherSource.php index 88168229a..4bcc20a5d 100644 --- a/lib/Cake/Test/test_app/Model/Datasource/Test2OtherSource.php +++ b/lib/Cake/Test/test_app/Model/Datasource/Test2OtherSource.php @@ -13,11 +13,11 @@ class Test2OtherSource extends DataSource { return compact('model', 'fields', 'values'); } - public function read(Model $model, $queryData = array()) { + public function read(Model $model, $queryData = array(), $recursive = null) { return compact('model', 'queryData'); } - public function update(Model $model, $fields = array(), $values = array()) { + public function update(Model $model, $fields = array(), $values = array(), $conditions = null) { return compact('model', 'fields', 'values'); } diff --git a/lib/Cake/Test/test_app/Model/Datasource/Test2Source.php b/lib/Cake/Test/test_app/Model/Datasource/Test2Source.php index bb9f1dc80..7f6eec4c7 100644 --- a/lib/Cake/Test/test_app/Model/Datasource/Test2Source.php +++ b/lib/Cake/Test/test_app/Model/Datasource/Test2Source.php @@ -13,11 +13,11 @@ class Test2Source extends DataSource { return compact('model', 'fields', 'values'); } - public function read(Model $model, $queryData = array()) { + public function read(Model $model, $queryData = array(), $recursive = null) { return compact('model', 'queryData'); } - public function update(Model $model, $fields = array(), $values = array()) { + public function update(Model $model, $fields = array(), $values = array(), $conditions = null) { return compact('model', 'fields', 'values'); } diff --git a/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestOtherSource.php b/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestOtherSource.php index 7ab6febca..7dde7f701 100644 --- a/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestOtherSource.php +++ b/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestOtherSource.php @@ -13,11 +13,11 @@ class TestOtherSource extends DataSource { return compact('model', 'fields', 'values'); } - public function read(Model $model, $queryData = array()) { + public function read(Model $model, $queryData = array(), $recursive = null) { return compact('model', 'queryData'); } - public function update(Model $model, $fields = array(), $values = array()) { + public function update(Model $model, $fields = array(), $values = array(), $conditions = null) { return compact('model', 'fields', 'values'); } diff --git a/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestSource.php b/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestSource.php index 371d86a98..7cd4a99ff 100644 --- a/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestSource.php +++ b/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/TestSource.php @@ -15,11 +15,11 @@ class TestSource extends DataSource { return compact('model', 'fields', 'values'); } - public function read(Model $model, $queryData = array()) { + public function read(Model $model, $queryData = array(), $recursive = null) { return compact('model', 'queryData'); } - public function update(Model $model, $fields = array(), $values = array()) { + public function update(Model $model, $fields = array(), $values = array(), $conditions = null) { return compact('model', 'fields', 'values'); } From 88604ac757198dbb2db55bd69e91060904c7b442 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Aug 2012 08:47:17 -0400 Subject: [PATCH 2/8] Replace is_a with instanceof. --- lib/Cake/View/Helper/JsHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/JsHelper.php b/lib/Cake/View/Helper/JsHelper.php index 93343dde1..00cf1756d 100644 --- a/lib/Cake/View/Helper/JsHelper.php +++ b/lib/Cake/View/Helper/JsHelper.php @@ -142,7 +142,7 @@ class JsHelper extends AppHelper { $this->buffer($out); return null; } - if (is_object($out) && is_a($out, 'JsBaseEngineHelper')) { + if (is_object($out) && $out instanceof JsBaseEngineHelper) { return $this; } return $out; From fb0053753e2629b3553fbaa1ba04b0eb78585467 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 22 Aug 2012 13:03:47 +0200 Subject: [PATCH 3/8] avoid duplication in returned results for habtm --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index c95ff26a8..c85dd85ca 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1755,7 +1755,7 @@ class Model extends Object implements CakeEventListener { $this->getEventManager()->dispatch($event); } if (!empty($this->data)) { - $success = Hash::merge($success, $this->data); + $success = array_merge($success, $this->data); } $this->data = false; $this->_clearCache(); diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index fe8714ee9..d46a6db27 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -1170,6 +1170,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); + $this->assertEquals($data['Tag'], $result['Tag']); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); From c5ebbc991c6609adfa824fca630826885328e8b1 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Thu, 23 Aug 2012 16:00:41 +0200 Subject: [PATCH 4/8] Revert "Merge pull request #784 from ceeram/habtmmerge" This reverts commit fa5aa6278f8a6df688462581fd8e0373ac4cbd54, reversing changes made to 88604ac757198dbb2db55bd69e91060904c7b442. --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index c85dd85ca..c95ff26a8 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1755,7 +1755,7 @@ class Model extends Object implements CakeEventListener { $this->getEventManager()->dispatch($event); } if (!empty($this->data)) { - $success = array_merge($success, $this->data); + $success = Hash::merge($success, $this->data); } $this->data = false; $this->_clearCache(); diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index d46a6db27..fe8714ee9 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -1170,7 +1170,6 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); - $this->assertEquals($data['Tag'], $result['Tag']); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); From cb80338c7d1761c699e7cb3151de30ad970d928a Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 24 Aug 2012 00:49:00 +0200 Subject: [PATCH 5/8] avoid duplication in return value when saving habtm --- lib/Cake/Model/Model.php | 3 +-- lib/Cake/Test/Case/Model/BehaviorCollectionTest.php | 1 + lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php | 1 - lib/Cake/Test/Case/Model/ModelWriteTest.php | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index c95ff26a8..515f2e5b3 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1745,7 +1745,6 @@ class Model extends Object implements CakeEventListener { if ($success && $count > 0) { if (!empty($this->data)) { - $success = $this->data; if ($created) { $this->data[$this->alias][$this->primaryKey] = $this->id; } @@ -1755,7 +1754,7 @@ class Model extends Object implements CakeEventListener { $this->getEventManager()->dispatch($event); } if (!empty($this->data)) { - $success = Hash::merge($success, $this->data); + $success = $this->data; } $this->data = false; $this->_clearCache(); diff --git a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php index b2b26b7f1..19497f7a6 100644 --- a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php +++ b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php @@ -888,6 +888,7 @@ class BehaviorCollectionTest extends CakeTestCase { $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test')); $Sample->create(); $expected = $record; + unset($expected['Sample']['name']); $result = $Sample->save($record); $expected['Sample']['id'] = $Sample->id; $this->assertSame($expected, $result); diff --git a/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php b/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php index 57f1bc3de..405bdb645 100644 --- a/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php +++ b/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php @@ -213,7 +213,6 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { 'Armor' => array( 'Armor' => array( 1, 2, 3, 4, - 1, 2, 3, 4, ), ), ); diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index fe8714ee9..d46a6db27 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -1170,6 +1170,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse(empty($result)); $result = $TestModel->save(); $this->assertFalse(empty($result)); + $this->assertEquals($data['Tag'], $result['Tag']); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2))); From dcc5a9548221b3dd42b72862bc664905cc1b0c4f Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 23 Aug 2012 23:11:00 -0400 Subject: [PATCH 6/8] Only split on ; for TABLE related statements. Fixes #3142 --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index bc3d7eb2c..8b5f3a436 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -447,7 +447,7 @@ class DboSource extends DataSource { */ protected function _execute($sql, $params = array(), $prepareOptions = array()) { $sql = trim($sql); - if (preg_match('/^(?:CREATE|ALTER|DROP)/i', $sql)) { + if (preg_match('/^(?:CREATE|ALTER|DROP)\s+TABLE/i', $sql)) { $statements = array_filter(explode(';', $sql)); if (count($statements) > 1) { $result = array_map(array($this, '_execute'), $statements); From b75a6b440abfbaf7af3ef82dd19eb4aff4be5847 Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Fri, 24 Aug 2012 12:08:21 -0300 Subject: [PATCH 7/8] Treat float numbers with trailing zeroes removed by PHP, accordingly. Revert #2800 (28bd6880df2f4a6bd182bcb0f3a04dd5a1b64fad) regex changes. Also add more tests. Signed-off-by: mark_story --- lib/Cake/Test/Case/Utility/ValidationTest.php | 10 +++++++--- lib/Cake/Utility/Validation.php | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index ddd07df21..6c87e08bf 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -1498,16 +1498,20 @@ class ValidationTest extends CakeTestCase { $this->assertTrue(Validation::decimal('+0123.45e6')); $this->assertTrue(Validation::decimal('-0123.45e6')); $this->assertTrue(Validation::decimal('0123.45e6')); - $this->assertTrue(Validation::decimal('1234')); - $this->assertTrue(Validation::decimal('-1234')); - $this->assertTrue(Validation::decimal('+1234')); $this->assertTrue(Validation::decimal(1234.56)); $this->assertTrue(Validation::decimal(1234.00)); + $this->assertTrue(Validation::decimal('1234.00')); $this->assertTrue(Validation::decimal(.0)); $this->assertTrue(Validation::decimal(.00)); + $this->assertTrue(Validation::decimal('.00')); $this->assertTrue(Validation::decimal(.01)); + $this->assertTrue(Validation::decimal('.01')); + $this->assertFalse(Validation::decimal('')); $this->assertFalse(Validation::decimal('string')); + $this->assertFalse(Validation::decimal('1234')); + $this->assertFalse(Validation::decimal('-1234')); + $this->assertFalse(Validation::decimal('+1234')); } /** diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index ea2b625bd..bb33e2605 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -381,11 +381,14 @@ class Validation { * @return boolean Success */ public static function decimal($check, $places = null, $regex = null) { + if (is_float($check) && floor($check) === $check) { + $check = sprintf("%.1f", $check); + } if (is_null($regex)) { if (is_null($places)) { - $regex = '/^[-+]?[0-9]*(\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?)?$/'; + $regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/'; } else { - $regex = '/^[-+]?[0-9]*(\\.{1}[0-9]{' . $places . '})?$/'; + $regex = '/^[-+]?[0-9]*\\.{1}[0-9]{' . $places . '}$/'; } } return self::_check($check, $regex); From b2f62f46c55d4a3f8fc363b2821e40e29084833e Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 24 Aug 2012 22:37:23 -0400 Subject: [PATCH 8/8] Fix failing tests in postgres. --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 8b5f3a436..64536c610 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -447,7 +447,7 @@ class DboSource extends DataSource { */ protected function _execute($sql, $params = array(), $prepareOptions = array()) { $sql = trim($sql); - if (preg_match('/^(?:CREATE|ALTER|DROP)\s+TABLE/i', $sql)) { + if (preg_match('/^(?:CREATE|ALTER|DROP)\s+(?:TABLE|INDEX)/i', $sql)) { $statements = array_filter(explode(';', $sql)); if (count($statements) > 1) { $result = array_map(array($this, '_execute'), $statements);