From 1e2ac0b9c8f8b00e322242bb24dca9e546d59fba Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 11 Oct 2012 14:03:59 +0200 Subject: [PATCH 1/6] comp mod for saveAll() better approach test case to assert saveAll still behaves like previous versions --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 28 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 9dd82b6b5..101fac91f 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2017,7 +2017,7 @@ class Model extends Object implements CakeEventListener { * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array */ - public function saveAll($data, $options = array()) { + public function saveAll($data = array(), $options = array()) { $options = array_merge(array('validate' => 'first'), $options); if (Hash::numeric(array_keys($data))) { if ($options['validate'] === 'only') { diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 31327e7de..c7976412e 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -4725,6 +4725,32 @@ class ModelWriteTest extends BaseModelTest { $this->assertEquals($expected, $TestModel->Comment->validationErrors); } +/** + * test that saveAll still behaves like previous versions (does not necessarily need a first argument) + * + * @return void + */ + public function testSaveAllWithSet() { + $this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag'); + $data = array( + 'Article' => array( + 'user_id' => 1, + 'title' => 'Article Has and belongs to Many Tags' + ), + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Comment' => array( + array( + 'comment' => 'Article comment', + 'user_id' => 1 + ))); + $Article = new Article(); + $Article->set($data); + $result = $Article->saveAll(); + $this->assertFalse(empty($result)); + } + /** * test that saveAll behaves like plain save() when supplied empty data * @@ -4740,7 +4766,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse(empty($result)); $model = new ProductUpdateAll(); - $result = $model->saveAll(array()); + $result = $model->saveAll(); $this->assertFalse($result); } From 9dc3b243ac33b19131a6ac28afabd7e945f72cda Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 22 Oct 2012 23:07:42 +0200 Subject: [PATCH 2/6] Correct inflection rules for cookies, fixes fixes #3291 --- lib/Cake/Test/Case/Utility/InflectorTest.php | 2 ++ lib/Cake/Utility/Inflector.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/InflectorTest.php b/lib/Cake/Test/Case/Utility/InflectorTest.php index cd1989248..acfd68cf8 100644 --- a/lib/Cake/Test/Case/Utility/InflectorTest.php +++ b/lib/Cake/Test/Case/Utility/InflectorTest.php @@ -109,6 +109,7 @@ class InflectorTest extends CakeTestCase { $this->assertEquals(Inflector::singularize('roofs'), 'roof'); $this->assertEquals(Inflector::singularize('foes'), 'foe'); $this->assertEquals(Inflector::singularize('databases'), 'database'); + $this->assertEquals(Inflector::singularize('cookies'), 'cookie'); $this->assertEquals(Inflector::singularize(''), ''); } @@ -160,6 +161,7 @@ class InflectorTest extends CakeTestCase { $this->assertEquals(Inflector::pluralize('cafe'), 'cafes'); $this->assertEquals(Inflector::pluralize('roof'), 'roofs'); $this->assertEquals(Inflector::pluralize('foe'), 'foes'); + $this->assertEquals(Inflector::pluralize('cookie'), 'cookie'); $this->assertEquals(Inflector::pluralize(''), ''); } diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 31829d621..47c591482 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -55,7 +55,7 @@ class Inflector { '/$/' => 's', ), 'uninflected' => array( - '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people' + '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie' ), 'irregular' => array( 'atlas' => 'atlases', @@ -63,6 +63,7 @@ class Inflector { 'brother' => 'brothers', 'cafe' => 'cafes', 'child' => 'children', + 'cookie' => 'cookies', 'corpus' => 'corpuses', 'cow' => 'cows', 'ganglion' => 'ganglions', From 1c0c8604c8ef45565a41170dd1f1dda181d7c1c2 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 22 Oct 2012 23:09:31 +0200 Subject: [PATCH 3/6] Pushed before fxing error in test case, I suck. Refs #3291 --- lib/Cake/Test/Case/Utility/InflectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/InflectorTest.php b/lib/Cake/Test/Case/Utility/InflectorTest.php index acfd68cf8..9e7d43add 100644 --- a/lib/Cake/Test/Case/Utility/InflectorTest.php +++ b/lib/Cake/Test/Case/Utility/InflectorTest.php @@ -161,7 +161,7 @@ class InflectorTest extends CakeTestCase { $this->assertEquals(Inflector::pluralize('cafe'), 'cafes'); $this->assertEquals(Inflector::pluralize('roof'), 'roofs'); $this->assertEquals(Inflector::pluralize('foe'), 'foes'); - $this->assertEquals(Inflector::pluralize('cookie'), 'cookie'); + $this->assertEquals(Inflector::pluralize('cookie'), 'cookies'); $this->assertEquals(Inflector::pluralize(''), ''); } From a0a61b5980272ec98dba0f02c9896d23a30d51fc Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 22 Oct 2012 20:33:43 -0400 Subject: [PATCH 4/6] Fix issue where createSchema() would omit primary keys sometimes. Fix missing primary key SQL when using the primary flag + other indexes. Fixes #3292 --- lib/Cake/Model/Datasource/DboSource.php | 2 +- .../Model/Datasource/Database/MysqlTest.php | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index ea1c7dbca..ef4bab7e7 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2984,7 +2984,7 @@ class DboSource extends DataSource { $tableParameters = array_merge($tableParameters, $this->buildTableParameters($col, $table)); } } - if (empty($indexes) && !empty($primary)) { + if (!isset($columns['indexes']['PRIMARY']) && !empty($primary)) { $col = array('PRIMARY' => array('column' => $primary, 'unique' => 1)); $indexes = array_merge($indexes, $this->buildIndex($col, $table)); } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index f14bf6116..4f3baa0bd 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -877,6 +877,52 @@ class MysqlTest extends CakeTestCase { $this->assertContains('`user_id` int(11) NOT NULL,', $result); } +/** + * Test that the primary flag is handled correctly. + * + * @return void + */ + public function testCreateSchemaAutoPrimaryKey() { + $schema = new CakeSchema(); + $schema->tables = array( + 'no_indexes' => array( + 'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'), + 'data' => array('type' => 'integer', 'null' => false), + 'indexes' => array(), + ) + ); + $result = $this->Dbo->createSchema($schema, 'no_indexes'); + $this->assertContains('PRIMARY KEY (`id`)', $result); + $this->assertNotContains('UNIQUE KEY', $result); + + $schema->tables = array( + 'primary_index' => array( + 'id' => array('type' => 'integer', 'null' => false), + 'data' => array('type' => 'integer', 'null' => false), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'some_index' => array('column' => 'data', 'unique' => 1) + ), + ) + ); + $result = $this->Dbo->createSchema($schema, 'primary_index'); + $this->assertContains('PRIMARY KEY (`id`)', $result); + $this->assertContains('UNIQUE KEY `some_index` (`data`)', $result); + + $schema->tables = array( + 'primary_flag_has_index' => array( + 'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'), + 'data' => array('type' => 'integer', 'null' => false), + 'indexes' => array ( + 'some_index' => array('column' => 'data', 'unique' => 1) + ), + ) + ); + $result = $this->Dbo->createSchema($schema, 'primary_flag_has_index'); + $this->assertContains('PRIMARY KEY (`id`)', $result); + $this->assertContains('UNIQUE KEY `some_index` (`data`)', $result); + } + /** * Tests that listSources method sends the correct query and parses the result accordingly * @return void From ed6ff92296107121d8fa50fb6ae75cd6ca61ca5e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Oct 2012 21:03:38 -0400 Subject: [PATCH 5/6] Remove bad test. --- lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php index a1c2abd5b..88a7b6143 100644 --- a/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php @@ -121,7 +121,6 @@ class MemcacheEngineTest extends CakeTestCase { $Memcache = new MemcacheEngine(); $Memcache->init(array('engine' => 'Memcache', 'servers' => $servers)); - $servers = array_keys($Memcache->__Memcache->getExtendedStats()); $settings = $Memcache->settings(); $this->assertEquals($settings['servers'], $servers); Cache::drop('dual_server'); From 922d9865fa22685b3f1ffada0158cf1446b5a761 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 23 Oct 2012 13:15:08 +0530 Subject: [PATCH 6/6] Moving multibyte encoding setting to bootstrap.php. Closes #3290 --- lib/Cake/I18n/I18n.php | 7 ------- lib/Cake/bootstrap.php | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 7678ba6ae..862414b7c 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -24,13 +24,6 @@ App::uses('CakePlugin', 'Core'); App::uses('L10n', 'I18n'); App::uses('Multibyte', 'I18n'); -if (function_exists('mb_internal_encoding')) { - $encoding = Configure::read('App.encoding'); - if (!empty($encoding)) { - mb_internal_encoding($encoding); - } -} - /** * I18n handles translation of Text and time format strings. * diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index 2c013b2d5..cd537cb5c 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -145,6 +145,12 @@ App::$bootstrapping = true; Configure::bootstrap(isset($boot) ? $boot : true); +if (function_exists('mb_internal_encoding')) { + $encoding = Configure::read('App.encoding'); + if (!empty($encoding)) { + mb_internal_encoding($encoding); + } +} /** * Full url prefix