Skip to content

Commit

Permalink
add translate behaviour test refs #9610
Browse files Browse the repository at this point in the history
  • Loading branch information
andrej-griniuk committed Oct 13, 2016
1 parent 9463399 commit 5bff3ce
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php
Expand Up @@ -45,6 +45,7 @@ class TranslateBehaviorTest extends TestCase
public $fixtures = [
'core.articles',
'core.authors',
'core.groups',
'core.special_tags',
'core.tags',
'core.comments',
Expand Down Expand Up @@ -1143,6 +1144,52 @@ public function testSaveNewRecordWithTranslatesField()
$this->assertEquals($expected, $this->_extractTranslations($result)->toArray());
}

/**
* Tests adding new translation to a record where the only field is the translated one
*
* @return void
*/
public function testSaveNewRecordWithOnlyTranslatesField()
{
$table = TableRegistry::get('Groups');
$table->addBehavior('Translate', [
'fields' => ['title'],
'validator' => (new \Cake\Validation\Validator)->add('title', 'notBlank', ['rule' => 'notBlank'])
]);
$table->entityClass(__NAMESPACE__ . '\Group');

$data = [
'_translations' => [
'en' => [
'title' => 'Title EN',
],
'es' => [
'title' => 'Title ES'
]
]
];

$group = $table->patchEntity($table->newEntity(), $data);
$result = $table->save($group);

$this->assertNotFalse($result);

$expected = [
[
'en' => [
'title' => 'Title EN',
'locale' => 'en'
],
'es' => [
'title' => 'Title ES',
'locale' => 'es'
]
]
];
$result = $table->find('translations')->where(['id' => $result->id]);
$this->assertEquals($expected, $this->_extractTranslations($result)->toArray());
}

/**
* Test update entity with _translations field.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/test_app/TestApp/Model/Entity/Group.php
@@ -0,0 +1,13 @@
<?php

namespace TestApp\Model\Entity;

use Cake\ORM\Entity;

/**
* Tests entity class used for asserting correct loading
*/
class Group extends Entity
{

}

0 comments on commit 5bff3ce

Please sign in to comment.