-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
TranslateTraitTest.php
80 lines (71 loc) · 2.44 KB
/
TranslateTraitTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Model\Behavior;
use Cake\Model\Behavior\Translate\TranslateTrait;
use Cake\ORM\Entity;
use Cake\TestSuite\TestCase;
class TestEntity extends Entity {
use TranslateTrait;
}
/**
* Translate behavior test case
*/
class TranslateBehaviorTest extends TestCase {
/**
* Tests that missing translation entries are created automatically
*
* @return void
*/
public function testTranslationCreate() {
$entity = new TestEntity;
$entity->translation('eng')->set('title', 'My Title');
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));
$this->assertTrue($entity->dirty('_translations'));
$entity->translation('spa')->set('body', 'Contenido');
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));
$this->assertEquals('Contenido', $entity->translation('spa')->get('body'));
}
/**
* Tests that modifying existing translation entries work
*
* @return void
*/
public function testTranslationModify() {
$entity = new TestEntity;
$entity->set('_translations', [
'eng' => new Entity(['title' => 'My Title']),
'spa' => new Entity(['title' => 'Titulo'])
]);
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));
$this->assertEquals('Titulo', $entity->translation('spa')->get('title'));
}
/**
* Tests that just accessing the translation will mark the property as dirty, this
* is to facilitate the saving process by not having to remember to mark the property
* manually
*
* @return void
*/
public function testTranslationDirty() {
$entity = new TestEntity;
$entity->set('_translations', [
'eng' => new Entity(['title' => 'My Title']),
'spa' => new Entity(['title' => 'Titulo'])
]);
$entity->clean();
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));
$this->assertTrue($entity->dirty('_translations'));
}
}