From 52f4cd42db5cfbdb466fe2415a268e751388ff70 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 19 Feb 2009 13:45:51 +0000 Subject: [PATCH] Fixing issue when Model::$translateTable is set git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8050 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/behaviors/translate.php | 2 ++ .../libs/model/behaviors/translate.test.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/cake/libs/model/behaviors/translate.php b/cake/libs/model/behaviors/translate.php index 353e504bc..7e959f50c 100644 --- a/cake/libs/model/behaviors/translate.php +++ b/cake/libs/model/behaviors/translate.php @@ -370,6 +370,8 @@ class TranslateBehavior extends ModelBehavior { } if (!empty($model->translateTable) && $model->translateTable !== $this->runtime[$model->alias]['model']->useTable) { $this->runtime[$model->alias]['model']->setSource($model->translateTable); + } elseif (empty($model->translateTable) && empty($model->translateModel)) { + $this->runtime[$model->alias]['model']->setSource('i18n'); } return $this->runtime[$model->alias]['model']; } diff --git a/cake/tests/cases/libs/model/behaviors/translate.test.php b/cake/tests/cases/libs/model/behaviors/translate.test.php index 9f7781c45..fe8eaa81f 100644 --- a/cake/tests/cases/libs/model/behaviors/translate.test.php +++ b/cake/tests/cases/libs/model/behaviors/translate.test.php @@ -64,6 +64,32 @@ class TranslateTest extends CakeTestCase { function endTest() { ClassRegistry::flush(); } +/** + * testTranslateModel method + * + * @access public + * @return void + */ + function testTranslateModel() { + $TestModel =& new Tag(); + $TestModel->translateTable = 'another_i18n'; + $TestModel->Behaviors->attach('Translate', array('title')); + $this->assertEqual($TestModel->translateModel()->name, 'I18nModel'); + $this->assertEqual($TestModel->translateModel()->useTable, 'another_i18n'); + + $TestModel =& new User(); + $TestModel->Behaviors->attach('Translate', array('title')); + $this->assertEqual($TestModel->translateModel()->name, 'I18nModel'); + $this->assertEqual($TestModel->translateModel()->useTable, 'i18n'); + + $TestModel =& new TranslatedArticle(); + $this->assertEqual($TestModel->translateModel()->name, 'TranslateArticleModel'); + $this->assertEqual($TestModel->translateModel()->useTable, 'article_i18n'); + + $TestModel =& new TranslatedItem(); + $this->assertEqual($TestModel->translateModel()->name, 'TranslateTestModel'); + $this->assertEqual($TestModel->translateModel()->useTable, 'i18n'); + } /** * testLocaleFalsePlain method *