Skip to content

Commit

Permalink
Add test for issue #2595
Browse files Browse the repository at this point in the history
Fold conditions that did the same thing and add a test case.

Closes #2595
  • Loading branch information
markstory committed Jan 7, 2014
1 parent a4f1388 commit 3763350
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 3763350

Please sign in to comment.