3
* TranslateBehaviorTest file
7
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
10
* Licensed under The Open Group Test Suite License
11
* Redistributions of files must retain the above copyright notice.
13
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
16
* @subpackage cake.tests.cases.libs.model.behaviors
17
* @since CakePHP(tm) v 1.2.0.5669
18
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
20
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
21
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
24
App::import('Core', array('AppModel', 'Model'));
25
require_once(dirname(dirname(__FILE__)) . DS . 'models.php');
28
* TranslateBehaviorTest class
31
* @subpackage cake.tests.cases.libs.model.behaviors
33
class TranslateBehaviorTest extends CakeTestCase {
36
* autoFixtures property
41
var $autoFixtures = false;
49
var $fixtures = array(
50
'core.translated_item', 'core.translate', 'core.translate_table',
51
'core.translated_article', 'core.translate_article', 'core.user', 'core.comment', 'core.tag', 'core.articles_tag',
52
'core.translate_with_prefix'
62
ClassRegistry::flush();
66
* testTranslateModel method
71
function testTranslateModel() {
72
$TestModel =& new Tag();
73
$TestModel->translateTable = 'another_i18n';
74
$TestModel->Behaviors->attach('Translate', array('title'));
75
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
76
$this->assertEqual($translateModel->name, 'I18nModel');
77
$this->assertEqual($translateModel->useTable, 'another_i18n');
79
$TestModel =& new User();
80
$TestModel->Behaviors->attach('Translate', array('title'));
81
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
82
$this->assertEqual($translateModel->name, 'I18nModel');
83
$this->assertEqual($translateModel->useTable, 'i18n');
85
$TestModel =& new TranslatedArticle();
86
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
87
$this->assertEqual($translateModel->name, 'TranslateArticleModel');
88
$this->assertEqual($translateModel->useTable, 'article_i18n');
90
$TestModel =& new TranslatedItem();
91
$translateModel =& $TestModel->Behaviors->Translate->translateModel($TestModel);
92
$this->assertEqual($translateModel->name, 'TranslateTestModel');
93
$this->assertEqual($translateModel->useTable, 'i18n');
97
* testLocaleFalsePlain method
102
function testLocaleFalsePlain() {
103
$this->loadFixtures('Translate', 'TranslatedItem');
105
$TestModel =& new TranslatedItem();
106
$TestModel->locale = false;
108
$result = $TestModel->read(null, 1);
109
$expected = array('TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'));
110
$this->assertEqual($result, $expected);
112
$result = $TestModel->find('all', array('fields' => array('slug')));
114
array('TranslatedItem' => array('slug' => 'first_translated')),
115
array('TranslatedItem' => array('slug' => 'second_translated')),
116
array('TranslatedItem' => array('slug' => 'third_translated'))
118
$this->assertEqual($result, $expected);
122
* testLocaleFalseAssociations method
127
function testLocaleFalseAssociations() {
128
$this->loadFixtures('Translate', 'TranslatedItem');
130
$TestModel =& new TranslatedItem();
131
$TestModel->locale = false;
132
$TestModel->unbindTranslation();
133
$translations = array('title' => 'Title', 'content' => 'Content');
134
$TestModel->bindTranslation($translations, false);
136
$result = $TestModel->read(null, 1);
138
'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'),
140
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
141
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
142
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1')
145
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
146
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
147
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1')
150
$this->assertEqual($result, $expected);
152
$TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content');
153
$TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng';
155
$result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug')));
158
'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'),
159
'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')),
160
'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1'))
163
'TranslatedItem' => array('id' => 2, 'slug' => 'second_translated'),
164
'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')),
165
'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2'))
168
'TranslatedItem' => array('id' => 3, 'slug' => 'third_translated'),
169
'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')),
170
'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3'))
173
$this->assertEqual($result, $expected);
177
* testLocaleSingle method
182
function testLocaleSingle() {
183
$this->loadFixtures('Translate', 'TranslatedItem');
185
$TestModel =& new TranslatedItem();
186
$TestModel->locale = 'eng';
187
$result = $TestModel->read(null, 1);
189
'TranslatedItem' => array(
191
'slug' => 'first_translated',
193
'title' => 'Title #1',
194
'content' => 'Content #1'
197
$this->assertEqual($result, $expected);
199
$result = $TestModel->find('all');
202
'TranslatedItem' => array(
204
'slug' => 'first_translated',
206
'title' => 'Title #1',
207
'content' => 'Content #1'
211
'TranslatedItem' => array(
213
'slug' => 'second_translated',
215
'title' => 'Title #2',
216
'content' => 'Content #2'
220
'TranslatedItem' => array(
222
'slug' => 'third_translated',
224
'title' => 'Title #3',
225
'content' => 'Content #3'
229
$this->assertEqual($result, $expected);
233
* testLocaleSingleWithConditions method
238
function testLocaleSingleWithConditions() {
239
$this->loadFixtures('Translate', 'TranslatedItem');
241
$TestModel =& new TranslatedItem();
242
$TestModel->locale = 'eng';
243
$result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated')));
246
'TranslatedItem' => array(
248
'slug' => 'first_translated',
250
'title' => 'Title #1',
251
'content' => 'Content #1'
255
$this->assertEqual($result, $expected);
257
$result = $TestModel->find('all', array('conditions' => "TranslatedItem.slug = 'first_translated'"));
260
'TranslatedItem' => array(
262
'slug' => 'first_translated',
264
'title' => 'Title #1',
265
'content' => 'Content #1'
269
$this->assertEqual($result, $expected);
273
* testLocaleSingleAssociations method
278
function testLocaleSingleAssociations() {
279
$this->loadFixtures('Translate', 'TranslatedItem');
281
$TestModel =& new TranslatedItem();
282
$TestModel->locale = 'eng';
283
$TestModel->unbindTranslation();
284
$translations = array('title' => 'Title', 'content' => 'Content');
285
$TestModel->bindTranslation($translations, false);
287
$result = $TestModel->read(null, 1);
289
'TranslatedItem' => array(
291
'slug' => 'first_translated',
293
'title' => 'Title #1',
294
'content' => 'Content #1'
297
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
298
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
299
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1')
302
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
303
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
304
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1')
307
$this->assertEqual($result, $expected);
309
$TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content');
310
$TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng';
312
$result = $TestModel->find('all', array('fields' => array('TranslatedItem.title')));
315
'TranslatedItem' => array('id' => 1, 'locale' => 'eng', 'title' => 'Title #1'),
316
'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')),
317
'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1'))
320
'TranslatedItem' => array('id' => 2, 'locale' => 'eng', 'title' => 'Title #2'),
321
'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')),
322
'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2'))
325
'TranslatedItem' => array('id' => 3, 'locale' => 'eng', 'title' => 'Title #3'),
326
'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')),
327
'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3'))
330
$this->assertEqual($result, $expected);
334
* testLocaleMultiple method
339
function testLocaleMultiple() {
340
$this->loadFixtures('Translate', 'TranslatedItem');
342
$TestModel =& new TranslatedItem();
343
$TestModel->locale = array('deu', 'eng', 'cze');
345
array('locale' => 'deu'),
346
array('foreign_key' => 1, 'field' => 'title', 'locale' => 'eng'),
347
array('foreign_key' => 1, 'field' => 'content', 'locale' => 'cze'),
348
array('foreign_key' => 2, 'field' => 'title', 'locale' => 'cze'),
349
array('foreign_key' => 2, 'field' => 'content', 'locale' => 'eng'),
350
array('foreign_key' => 3, 'field' => 'title')
352
$I18nModel =& ClassRegistry::getObject('TranslateTestModel');
353
$I18nModel->deleteAll(array('or' => $delete));
355
$result = $TestModel->read(null, 1);
357
'TranslatedItem' => array(
359
'slug' => 'first_translated',
361
'title' => 'Titulek #1',
362
'content' => 'Content #1'
365
$this->assertEqual($result, $expected);
367
$result = $TestModel->find('all', array('fields' => array('slug', 'title', 'content')));
370
'TranslatedItem' => array(
371
'slug' => 'first_translated',
373
'title' => 'Titulek #1',
374
'content' => 'Content #1'
378
'TranslatedItem' => array(
379
'slug' => 'second_translated',
381
'title' => 'Title #2',
382
'content' => 'Obsah #2'
386
'TranslatedItem' => array(
387
'slug' => 'third_translated',
390
'content' => 'Content #3'
394
$this->assertEqual($result, $expected);
398
* testMissingTranslation method
403
function testMissingTranslation() {
404
$this->loadFixtures('Translate', 'TranslatedItem');
406
$TestModel =& new TranslatedItem();
407
$TestModel->locale = 'rus';
408
$result = $TestModel->read(null, 1);
409
$this->assertFalse($result);
411
$TestModel->locale = array('rus');
412
$result = $TestModel->read(null, 1);
414
'TranslatedItem' => array(
416
'slug' => 'first_translated',
422
$this->assertEqual($result, $expected);
426
* testTranslatedFindList method
431
function testTranslatedFindList() {
432
$this->loadFixtures('Translate', 'TranslatedItem');
434
$TestModel =& new TranslatedItem();
435
$TestModel->locale = 'deu';
436
$TestModel->displayField = 'title';
437
$result = $TestModel->find('list', array('recursive' => 1));
438
$expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3');
439
$this->assertEqual($result, $expected);
441
// MSSQL trigger an error and stops the page even if the debug = 0
442
if ($this->db->config['driver'] != 'mssql') {
443
$debug = Configure::read('debug');
444
Configure::write('debug', 0);
446
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
447
$this->assertEqual($result, array());
449
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
450
$this->assertEqual($result, array());
451
Configure::write('debug', $debug);
454
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before'));
455
$expected = array(1 => null, 2 => null, 3 => null);
456
$this->assertEqual($result, $expected);
460
* testReadSelectedFields method
465
function testReadSelectedFields() {
466
$this->loadFixtures('Translate', 'TranslatedItem');
468
$TestModel =& new TranslatedItem();
469
$TestModel->locale = 'eng';
470
$result = $TestModel->find('all', array('fields' => array('slug', 'TranslatedItem.content')));
472
array('TranslatedItem' => array('slug' => 'first_translated', 'locale' => 'eng', 'content' => 'Content #1')),
473
array('TranslatedItem' => array('slug' => 'second_translated', 'locale' => 'eng', 'content' => 'Content #2')),
474
array('TranslatedItem' => array('slug' => 'third_translated', 'locale' => 'eng', 'content' => 'Content #3'))
476
$this->assertEqual($result, $expected);
478
$result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug', 'content')));
479
$this->assertEqual($result, $expected);
481
$TestModel->locale = array('eng', 'deu', 'cze');
482
$delete = array(array('locale' => 'deu'), array('field' => 'content', 'locale' => 'eng'));
483
$I18nModel =& ClassRegistry::getObject('TranslateTestModel');
484
$I18nModel->deleteAll(array('or' => $delete));
486
$result = $TestModel->find('all', array('fields' => array('title', 'content')));
488
array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #1', 'content' => 'Obsah #1')),
489
array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #2', 'content' => 'Obsah #2')),
490
array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #3', 'content' => 'Obsah #3'))
492
$this->assertEqual($result, $expected);
496
* testSaveCreate method
501
function testSaveCreate() {
502
$this->loadFixtures('Translate', 'TranslatedItem');
504
$TestModel =& new TranslatedItem();
505
$TestModel->locale = 'spa';
506
$data = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'content' => 'Contenido #4');
507
$TestModel->create($data);
509
$result = $TestModel->read();
510
$expected = array('TranslatedItem' => array_merge($data, array('id' => $TestModel->id, 'locale' => 'spa')));
511
$this->assertEqual($result, $expected);
515
* testSaveUpdate method
520
function testSaveUpdate() {
521
$this->loadFixtures('Translate', 'TranslatedItem');
523
$TestModel =& new TranslatedItem();
524
$TestModel->locale = 'spa';
525
$oldData = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4');
526
$TestModel->create($oldData);
528
$id = $TestModel->id;
529
$newData = array('id' => $id, 'content' => 'Contenido #4');
530
$TestModel->create($newData);
532
$result = $TestModel->read(null, $id);
533
$expected = array('TranslatedItem' => array_merge($oldData, $newData, array('locale' => 'spa')));
534
$this->assertEqual($result, $expected);
538
* testMultipleCreate method
543
function testMultipleCreate() {
544
$this->loadFixtures('Translate', 'TranslatedItem');
546
$TestModel =& new TranslatedItem();
547
$TestModel->locale = 'deu';
549
'slug' => 'new_translated',
550
'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
551
'content' => array('eng' => 'New content', 'spa' => 'Nuevo contenido')
553
$TestModel->create($data);
556
$TestModel->unbindTranslation();
557
$translations = array('title' => 'Title', 'content' => 'Content');
558
$TestModel->bindTranslation($translations, false);
559
$TestModel->locale = array('eng', 'spa');
561
$result = $TestModel->read();
563
'TranslatedItem' => array('id' => 4, 'slug' => 'new_translated', 'locale' => 'eng', 'title' => 'New title', 'content' => 'New content'),
565
array('id' => 21, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'New title'),
566
array('id' => 22, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'Nuevo leyenda')
569
array('id' => 19, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'New content'),
570
array('id' => 20, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'Nuevo contenido')
573
$this->assertEqual($result, $expected);
577
* testMultipleUpdate method
582
function testMultipleUpdate() {
583
$this->loadFixtures('Translate', 'TranslatedItem');
585
$TestModel =& new TranslatedItem();
586
$TestModel->locale = 'eng';
587
$TestModel->validate['title'] = 'notEmpty';
588
$data = array('TranslatedItem' => array(
590
'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
591
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
593
$TestModel->create();
594
$TestModel->save($data);
596
$TestModel->unbindTranslation();
597
$translations = array('title' => 'Title', 'content' => 'Content');
598
$TestModel->bindTranslation($translations, false);
599
$result = $TestModel->read(null, 1);
601
'TranslatedItem' => array('id' => '1', 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'New Title #1', 'content' => 'New Content #1'),
603
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'New Title #1'),
604
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Neue Titel #1'),
605
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Novy Titulek #1')
608
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'New Content #1'),
609
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Neue Inhalt #1'),
610
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Novy Obsah #1')
613
$this->assertEqual($result, $expected);
615
$TestModel->unbindTranslation($translations);
616
$TestModel->bindTranslation(array('title', 'content'), false);
620
* testMixedCreateUpdateWithArrayLocale method
625
function testMixedCreateUpdateWithArrayLocale() {
626
$this->loadFixtures('Translate', 'TranslatedItem');
628
$TestModel =& new TranslatedItem();
629
$TestModel->locale = array('cze', 'deu');
630
$data = array('TranslatedItem' => array(
632
'title' => array('eng' => 'Updated Title #1', 'spa' => 'Nuevo leyenda #1'),
633
'content' => 'Upraveny obsah #1'
635
$TestModel->create();
636
$TestModel->save($data);
638
$TestModel->unbindTranslation();
639
$translations = array('title' => 'Title', 'content' => 'Content');
640
$TestModel->bindTranslation($translations, false);
641
$result = $TestModel->read(null, 1);
643
'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated', 'locale' => 'cze', 'title' => 'Titulek #1', 'content' => 'Upraveny obsah #1'),
645
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Updated Title #1'),
646
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
647
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'),
648
array('id' => 19, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Nuevo leyenda #1')
651
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
652
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
653
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Upraveny obsah #1')
656
$this->assertEqual($result, $expected);
660
* testValidation method
665
function testValidation() {
666
$this->loadFixtures('Translate', 'TranslatedItem');
668
$TestModel =& new TranslatedItem();
669
$TestModel->locale = 'eng';
670
$TestModel->validate['title'] = '/Only this title/';
671
$data = array('TranslatedItem' => array(
673
'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
674
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
676
$TestModel->create();
677
$this->assertFalse($TestModel->save($data));
678
$this->assertEqual($TestModel->validationErrors['title'], 'This field cannot be left blank');
680
$TestModel->locale = 'eng';
681
$TestModel->validate['title'] = '/Only this title/';
682
$data = array('TranslatedItem' => array(
684
'title' => array('eng' => 'Only this title', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
685
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
687
$TestModel->create();
688
$this->assertTrue($TestModel->save($data));
692
* testAttachDetach method
697
function testAttachDetach() {
698
$this->loadFixtures('Translate', 'TranslatedItem');
700
$TestModel =& new TranslatedItem();
701
$Behavior =& $this->Model->Behaviors->Translate;
703
$TestModel->unbindTranslation();
704
$translations = array('title' => 'Title', 'content' => 'Content');
705
$TestModel->bindTranslation($translations, false);
707
$result = array_keys($TestModel->hasMany);
708
$expected = array('Title', 'Content');
709
$this->assertEqual($result, $expected);
711
$TestModel->Behaviors->detach('Translate');
712
$result = array_keys($TestModel->hasMany);
714
$this->assertEqual($result, $expected);
716
$result = isset($TestModel->Behaviors->Translate);
717
$this->assertFalse($result);
719
$result = isset($Behavior->settings[$TestModel->alias]);
720
$this->assertFalse($result);
722
$result = isset($Behavior->runtime[$TestModel->alias]);
723
$this->assertFalse($result);
725
$TestModel->Behaviors->attach('Translate', array('title' => 'Title', 'content' => 'Content'));
726
$result = array_keys($TestModel->hasMany);
727
$expected = array('Title', 'Content');
728
$this->assertEqual($result, $expected);
730
$result = isset($TestModel->Behaviors->Translate);
731
$this->assertTrue($result);
733
$Behavior = $TestModel->Behaviors->Translate;
735
$result = isset($Behavior->settings[$TestModel->alias]);
736
$this->assertTrue($result);
738
$result = isset($Behavior->runtime[$TestModel->alias]);
739
$this->assertTrue($result);
743
* testAnotherTranslateTable method
748
function testAnotherTranslateTable() {
749
$this->loadFixtures('Translate', 'TranslatedItem', 'TranslateTable');
751
$TestModel =& new TranslatedItemWithTable();
752
$TestModel->locale = 'eng';
753
$result = $TestModel->read(null, 1);
755
'TranslatedItemWithTable' => array(
757
'slug' => 'first_translated',
759
'title' => 'Another Title #1',
760
'content' => 'Another Content #1'
763
$this->assertEqual($result, $expected);
767
* testTranslateWithAssociations method
772
function testTranslateWithAssociations() {
773
$this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User', 'Comment', 'ArticlesTag', 'Tag');
775
$TestModel =& new TranslatedArticle();
776
$TestModel->locale = 'eng';
777
$recursive = $TestModel->recursive;
779
$result = $TestModel->read(null, 1);
781
'TranslatedArticle' => array(
785
'created' => '2007-03-18 10:39:23',
786
'updated' => '2007-03-18 10:41:31',
788
'title' => 'Title (eng) #1',
789
'body' => 'Body (eng) #1'
794
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
795
'created' => '2007-03-17 01:16:23',
796
'updated' => '2007-03-17 01:18:31'
799
$this->assertEqual($result, $expected);
801
$result = $TestModel->find('all', array('recursive' => -1));
804
'TranslatedArticle' => array(
808
'created' => '2007-03-18 10:39:23',
809
'updated' => '2007-03-18 10:41:31',
811
'title' => 'Title (eng) #1',
812
'body' => 'Body (eng) #1'
816
'TranslatedArticle' => array(
820
'created' => '2007-03-18 10:41:23',
821
'updated' => '2007-03-18 10:43:31',
823
'title' => 'Title (eng) #2',
824
'body' => 'Body (eng) #2'
828
'TranslatedArticle' => array(
832
'created' => '2007-03-18 10:43:23',
833
'updated' => '2007-03-18 10:45:31',
835
'title' => 'Title (eng) #3',
836
'body' => 'Body (eng) #3'
840
$this->assertEqual($result, $expected);
841
$this->assertEqual($TestModel->recursive, $recursive);
843
$TestModel->recursive = -1;
844
$result = $TestModel->read(null, 1);
846
'TranslatedArticle' => array(
850
'created' => '2007-03-18 10:39:23',
851
'updated' => '2007-03-18 10:41:31',
853
'title' => 'Title (eng) #1',
854
'body' => 'Body (eng) #1'
857
$this->assertEqual($result, $expected);
860
* testTranslateTableWithPrefix method
861
* Tests that is possible to have a translation model with a custom tablePrefix
866
function testTranslateTableWithPrefix() {
867
$this->loadFixtures('TranslateWithPrefix', 'TranslatedItem');
868
$TestModel =& new TranslatedItem2;
869
$TestModel->locale = 'eng';
870
$result = $TestModel->read(null, 1);
871
$expected = array('TranslatedItem' => array(
873
'slug' => 'first_translated',
875
'content' => 'Content #1',
876
'title' => 'Title #1'
878
$this->assertEqual($result, $expected);
882
* Test infinite loops not occuring with unbindTranslation()
886
function testUnbindTranslationInfinteLoop() {
887
$this->loadFixtures('Translate', 'TranslatedItem');
889
$TestModel =& new TranslatedItem();
890
$TestModel->Behaviors->detach('Translate');
891
$TestModel->actsAs = array();
892
$TestModel->Behaviors->attach('Translate');
893
$TestModel->bindTranslation(array('title', 'content'), true);
894
$result = $TestModel->unbindTranslation();
896
$this->assertFalse($result);