From 3763350667f3175296bf1c69bbdb63e7290d32ec Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 6 Jan 2014 21:21:13 -0500 Subject: [PATCH] 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 *