Add test for issue #2595

Fold conditions that did the same thing and add a test case.

Closes #2595
This commit is contained in:
mark_story 2014-01-06 21:21:13 -05:00
parent a4f138813b
commit 3763350667
2 changed files with 26 additions and 3 deletions

View file

@ -305,9 +305,7 @@ class TranslateBehavior extends ModelBehavior {
} }
} else { } else {
$value = ''; $value = '';
if (is_numeric($row[$Model->alias][$aliasVirtual])) { if (is_numeric($row[$Model->alias][$aliasVirtual]) || !empty($row[$Model->alias][$aliasVirtual])) {
$value = $row[$Model->alias][$aliasVirtual];
} elseif (!empty($row[$Model->alias][$aliasVirtual])) {
$value = $row[$Model->alias][$aliasVirtual]; $value = $row[$Model->alias][$aliasVirtual];
} }
$row[$Model->alias][$aliasField] = $value; $row[$Model->alias][$aliasField] = $value;

View file

@ -354,6 +354,31 @@ class TranslateBehaviorTest extends CakeTestCase {
$this->assertEquals($expected, $result); $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 * testLocaleMultiple method
* *