Skip to content

Commit

Permalink
Added test for adding translations to a record
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 10, 2014
1 parent 8935530 commit f7553b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Model/Behavior/TranslateBehavior.php
Expand Up @@ -171,8 +171,9 @@ public function beforeSave(Event $event, $entity) {
}

$new = array_diff_key($values, $modified);
$model = $this->_table->alias();
foreach ($new as $field => $content) {
$new[$field] = new Entity(compact('locale', 'field', 'content'), [
$new[$field] = new Entity(compact('locale', 'field', 'content', 'model'), [
'useSetters' => false,
'markNew' => true
]);
Expand Down
29 changes: 29 additions & 0 deletions tests/TestCase/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -491,4 +491,33 @@ public function testUpdateSingleLocale() {
$this->assertEquals('A translated body', $article->get('body'));
}

/**
* Tests adding new translation to a record
*
* @return void
*/
public function testInsertNewTranslations() {
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$table->locale('fra');

$article = $table->find()->first();
$this->assertEquals(1, $article->get('id'));
$article->set('title', 'Le titre');
$table->save($article);

$article = $table->find()->first();
$this->assertEquals(1, $article->get('id'));
$this->assertEquals('Le titre', $article->get('title'));
$this->assertEquals('First Article Body', $article->get('body'));

$article->set('title', 'Un autre titre');
$article->set('body', 'Le contenu');
$table->save($article);

$article = $table->find()->first();
$this->assertEquals('Un autre titre', $article->get('title'));
$this->assertEquals('Le contenu', $article->get('body'));
}

}

0 comments on commit f7553b0

Please sign in to comment.