Skip to content

Commit

Permalink
Adding more tests for TranslateBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 26, 2014
1 parent f2d58a5 commit 2a9c9ff
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/TestCase/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -340,4 +340,57 @@ public function testTranslationsHasMany() {
$this->assertEquals($expected, $translations->toArray());
}

/**
* Tests that it is possible to both override fields with a translation and
* also find separately other translations
*
* @return void
*/
public function testTranslationsHasManyWithOverride() {
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$table->hasMany('Comments');
$comments = $table->hasMany('Comments')->target();
$comments->addBehavior('Translate', ['fields' => ['comment']]);

$table->locale('cze');
$comments->locale('eng');
$results = $table->find('translations')->contain([
'Comments' => function($q) {
return $q->find('translations')->select(['id', 'comment', 'article_id']);
}
]);

$comments = $results->first()->comments;
$expected = [
1 => 'Comment #1',
2 => 'Comment #2',
3 => 'Comment #3',
4 => 'Comment #4'
];
$list = new Collection($comments);
$this->assertEquals($expected, $list->combine('id', 'comment')->toArray());

$expected = [
[
'eng' => ['comment' => 'Comment #1', 'locale' => 'eng']
],
[
'eng' => ['comment' => 'Comment #2', 'locale' => 'eng']
],
[
'eng' => ['comment' => 'Comment #3', 'locale' => 'eng']
],
[
'eng' => ['comment' => 'Comment #4', 'locale' => 'eng'],
'spa' => ['comment' => 'Comentario #4', 'locale' => 'spa']
]
];
$translations = $this->_extractTranslations($comments);
$this->assertEquals($expected, $translations->toArray());

$this->assertEquals('Titulek #1', $results->first()->title);
$this->assertEquals('Obsah #1', $results->first()->body);
}

}

0 comments on commit 2a9c9ff

Please sign in to comment.