Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
4
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice
9
 *
10
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11
 * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
12
 * @since         CakePHP(tm) v 1.2.0.5669
13
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
 
16
App::uses('Model', 'Model');
17
App::uses('AppModel', 'Model');
18
 
19
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
20
 
21
/**
22
 * TranslateBehaviorTest class
23
 *
24
 * @package       Cake.Test.Case.Model.Behavior
25
 */
26
class TranslateBehaviorTest extends CakeTestCase {
27
 
28
/**
29
 * autoFixtures property
30
 *
31
 * @var boolean
32
 */
33
	public $autoFixtures = false;
34
 
35
/**
36
 * fixtures property
37
 *
38
 * @var array
39
 */
40
	public $fixtures = array(
41
		'core.translated_item', 'core.translate', 'core.translate_table',
42
		'core.translated_article', 'core.translate_article', 'core.user', 'core.comment', 'core.tag', 'core.articles_tag',
43
		'core.translate_with_prefix'
44
	);
45
 
46
/**
47
 * Test that count queries with conditions get the correct joins
48
 *
49
 * @return void
50
 */
51
	public function testCountWithConditions() {
52
		$this->loadFixtures('Translate', 'TranslatedItem');
53
 
54
		$Model = new TranslatedItem();
55
		$Model->locale = 'eng';
56
		$result = $Model->find('count', array(
57
			'conditions' => array(
58
				'I18n__content.locale' => 'eng'
59
			)
60
		));
61
		$this->assertEquals(3, $result);
62
	}
63
 
64
/**
65
 * testTranslateModel method
66
 *
67
 * @return void
68
 */
69
	public function testTranslateModel() {
70
		$this->loadFixtures('TranslateTable', 'Tag', 'TranslatedItem', 'Translate', 'User', 'TranslatedArticle', 'TranslateArticle');
71
		$TestModel = new Tag();
72
		$TestModel->translateTable = 'another_i18n';
73
		$TestModel->Behaviors->load('Translate', array('title'));
74
		$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
75
		$this->assertEquals('I18nModel', $translateModel->name);
76
		$this->assertEquals('another_i18n', $translateModel->useTable);
77
 
78
		$TestModel = new User();
79
		$TestModel->Behaviors->load('Translate', array('title'));
80
		$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
81
		$this->assertEquals('I18nModel', $translateModel->name);
82
		$this->assertEquals('i18n', $translateModel->useTable);
83
 
84
		$TestModel = new TranslatedArticle();
85
		$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
86
		$this->assertEquals('TranslateArticleModel', $translateModel->name);
87
		$this->assertEquals('article_i18n', $translateModel->useTable);
88
 
89
		$TestModel = new TranslatedItem();
90
		$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
91
		$this->assertEquals('TranslateTestModel', $translateModel->name);
92
		$this->assertEquals('i18n', $translateModel->useTable);
93
	}
94
 
95
/**
96
 * testLocaleFalsePlain method
97
 *
98
 * @return void
99
 */
100
	public function testLocaleFalsePlain() {
101
		$this->loadFixtures('Translate', 'TranslatedItem', 'User');
102
 
103
		$TestModel = new TranslatedItem();
104
		$TestModel->locale = false;
105
 
106
		$result = $TestModel->read(null, 1);
107
		$expected = array('TranslatedItem' => array(
108
			'id' => 1,
109
			'slug' => 'first_translated',
110
			'translated_article_id' => 1,
111
		));
112
		$this->assertEquals($expected, $result);
113
 
114
		$result = $TestModel->find('all', array('fields' => array('slug')));
115
		$expected = array(
116
			array('TranslatedItem' => array('slug' => 'first_translated')),
117
			array('TranslatedItem' => array('slug' => 'second_translated')),
118
			array('TranslatedItem' => array('slug' => 'third_translated'))
119
		);
120
		$this->assertEquals($expected, $result);
121
	}
122
 
123
/**
124
 * testLocaleFalseAssociations method
125
 *
126
 * @return void
127
 */
128
	public function testLocaleFalseAssociations() {
129
		$this->loadFixtures('Translate', 'TranslatedItem');
130
 
131
		$TestModel = new TranslatedItem();
132
		$TestModel->locale = false;
133
		$TestModel->unbindTranslation();
134
		$translations = array('title' => 'Title', 'content' => 'Content');
135
		$TestModel->bindTranslation($translations, false);
136
 
137
		$result = $TestModel->read(null, 1);
138
		$expected = array(
139
			'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated', 'translated_article_id' => 1),
140
			'Title' => array(
141
				array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
142
				array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
143
				array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1')
144
			),
145
			'Content' => array(
146
				array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
147
				array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
148
				array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1')
149
			)
150
		);
151
		$this->assertEquals($expected, $result);
152
 
153
		$TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content');
154
		$TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng';
155
 
156
		$result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug')));
157
		$expected = array(
158
			array(
159
				'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'),
160
				'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')),
161
				'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1'))
162
			),
163
			array(
164
				'TranslatedItem' => array('id' => 2, 'slug' => 'second_translated'),
165
				'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')),
166
				'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2'))
167
			),
168
			array(
169
				'TranslatedItem' => array('id' => 3, 'slug' => 'third_translated'),
170
				'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')),
171
				'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3'))
172
			)
173
		);
174
		$this->assertEquals($expected, $result);
175
	}
176
 
177
/**
178
 * testLocaleSingle method
179
 *
180
 * @return void
181
 */
182
	public function testLocaleSingle() {
183
		$this->loadFixtures('Translate', 'TranslatedItem');
184
 
185
		$TestModel = new TranslatedItem();
186
		$TestModel->locale = 'eng';
187
 
188
		$result = $TestModel->read(null, 1);
189
		$expected = array(
190
			'TranslatedItem' => array(
191
				'id' => 1,
192
				'slug' => 'first_translated',
193
				'locale' => 'eng',
194
				'title' => 'Title #1',
195
				'content' => 'Content #1',
196
				'translated_article_id' => 1,
197
			)
198
		);
199
		$this->assertEquals($expected, $result);
200
 
201
		$result = $TestModel->find('all');
202
		$expected = array(
203
			array(
204
				'TranslatedItem' => array(
205
					'id' => 1,
206
					'slug' => 'first_translated',
207
					'locale' => 'eng',
208
					'title' => 'Title #1',
209
					'content' => 'Content #1',
210
					'translated_article_id' => 1,
211
				)
212
			),
213
			array(
214
				'TranslatedItem' => array(
215
					'id' => 2,
216
					'slug' => 'second_translated',
217
					'locale' => 'eng',
218
					'title' => 'Title #2',
219
					'content' => 'Content #2',
220
					'translated_article_id' => 1,
221
				)
222
			),
223
			array(
224
				'TranslatedItem' => array(
225
					'id' => 3,
226
					'slug' => 'third_translated',
227
					'locale' => 'eng',
228
					'title' => 'Title #3',
229
					'content' => 'Content #3',
230
					'translated_article_id' => 1,
231
				)
232
			)
233
		);
234
		$this->assertEquals($expected, $result);
235
	}
236
 
237
/**
238
 * testLocaleSingleWithConditions method
239
 *
240
 * @return void
241
 */
242
	public function testLocaleSingleWithConditions() {
243
		$this->loadFixtures('Translate', 'TranslatedItem');
244
 
245
		$TestModel = new TranslatedItem();
246
		$TestModel->locale = 'eng';
247
		$result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated')));
248
		$expected = array(
249
			array(
250
				'TranslatedItem' => array(
251
					'id' => 1,
252
					'slug' => 'first_translated',
253
					'locale' => 'eng',
254
					'title' => 'Title #1',
255
					'content' => 'Content #1',
256
					'translated_article_id' => 1,
257
				)
258
			)
259
		);
260
		$this->assertEquals($expected, $result);
261
 
262
		$result = $TestModel->find('all', array('conditions' => "TranslatedItem.slug = 'first_translated'"));
263
		$expected = array(
264
			array(
265
				'TranslatedItem' => array(
266
					'id' => 1,
267
					'slug' => 'first_translated',
268
					'locale' => 'eng',
269
					'title' => 'Title #1',
270
					'content' => 'Content #1',
271
					'translated_article_id' => 1,
272
				)
273
			)
274
		);
275
		$this->assertEquals($expected, $result);
276
	}
277
 
278
/**
279
 * testLocaleSingleAssociations method
280
 *
281
 * @return void
282
 */
283
	public function testLocaleSingleAssociations() {
284
		$this->loadFixtures('Translate', 'TranslatedItem');
285
 
286
		$TestModel = new TranslatedItem();
287
		$TestModel->locale = 'eng';
288
		$TestModel->unbindTranslation();
289
		$translations = array('title' => 'Title', 'content' => 'Content');
290
		$TestModel->bindTranslation($translations, false);
291
 
292
		$result = $TestModel->read(null, 1);
293
		$expected = array(
294
			'TranslatedItem' => array(
295
				'id' => 1,
296
				'slug' => 'first_translated',
297
				'locale' => 'eng',
298
				'title' => 'Title #1',
299
				'content' => 'Content #1',
300
				'translated_article_id' => 1,
301
			),
302
			'Title' => array(
303
				array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
304
				array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
305
				array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1')
306
			),
307
			'Content' => array(
308
				array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
309
				array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
310
				array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1')
311
			)
312
		);
313
		$this->assertEquals($expected, $result);
314
 
315
		$TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content');
316
		$TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng';
317
 
318
		$result = $TestModel->find('all', array('fields' => array('TranslatedItem.title')));
319
		$expected = array(
320
			array(
321
				'TranslatedItem' => array(
322
					'id' => 1,
323
					'locale' => 'eng',
324
					'title' => 'Title #1',
325
					'slug' => 'first_translated',
326
					'translated_article_id' => 1,
327
				),
328
				'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')),
329
				'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1'))
330
			),
331
			array(
332
				'TranslatedItem' => array(
333
					'id' => 2,
334
					'locale' => 'eng',
335
					'title' => 'Title #2',
336
					'slug' => 'second_translated',
337
					'translated_article_id' => 1,
338
				),
339
				'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')),
340
				'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2'))
341
			),
342
			array(
343
				'TranslatedItem' => array(
344
					'id' => 3,
345
					'locale' => 'eng',
346
					'title' => 'Title #3',
347
					'slug' => 'third_translated',
348
					'translated_article_id' => 1,
349
				),
350
				'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')),
351
				'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3'))
352
			)
353
		);
354
		$this->assertEquals($expected, $result);
355
	}
356
 
357
/**
358
 * testLocaleMultiple method
359
 *
360
 * @return void
361
 */
362
	public function testLocaleMultiple() {
363
		$this->loadFixtures('Translate', 'TranslatedItem');
364
 
365
		$TestModel = new TranslatedItem();
366
		$TestModel->locale = array('deu', 'eng', 'cze');
367
 
368
		$result = $TestModel->read(null, 1);
369
		$expected = array(
370
			'TranslatedItem' => array(
371
				'id' => 1,
372
				'slug' => 'first_translated',
373
				'locale' => 'deu',
374
				'title' => 'Titel #1',
375
				'content' => 'Inhalt #1',
376
				'translated_article_id' => 1,
377
			)
378
		);
379
		$this->assertEquals($expected, $result);
380
 
381
		$result = $TestModel->find('all', array('fields' => array('slug', 'title', 'content')));
382
		$expected = array(
383
			array(
384
				'TranslatedItem' => array(
385
					'slug' => 'first_translated',
386
					'locale' => 'deu',
387
					'content' => 'Inhalt #1',
388
					'title' => 'Titel #1',
389
				)
390
			),
391
			array(
392
				'TranslatedItem' => array(
393
					'slug' => 'second_translated',
394
					'locale' => 'deu',
395
					'title' => 'Titel #2',
396
					'content' => 'Inhalt #2',
397
				)
398
			),
399
			array(
400
				'TranslatedItem' => array(
401
					'slug' => 'third_translated',
402
					'locale' => 'deu',
403
					'title' => 'Titel #3',
404
					'content' => 'Inhalt #3',
405
				)
406
			)
407
		);
408
		$this->assertEquals($expected, $result);
409
 
410
		$TestModel = new TranslatedItem();
411
		$TestModel->locale = array('pt-br');
412
		$result = $TestModel->find('all');
413
		$this->assertCount(3, $result, '3 records should have been found, no SQL error.');
414
	}
415
 
416
/**
417
 * testMissingTranslation method
418
 *
419
 * @return void
420
 */
421
	public function testMissingTranslation() {
422
		$this->loadFixtures('Translate', 'TranslatedItem');
423
 
424
		$TestModel = new TranslatedItem();
425
		$TestModel->locale = 'rus';
426
		$result = $TestModel->read(null, 1);
427
		$this->assertSame(array(), $result);
428
 
429
		$TestModel->locale = array('rus');
430
		$result = $TestModel->read(null, 1);
431
		$expected = array(
432
			'TranslatedItem' => array(
433
				'id' => 1,
434
				'slug' => 'first_translated',
435
				'locale' => 'rus',
436
				'title' => '',
437
				'content' => '',
438
				'translated_article_id' => 1,
439
			)
440
		);
441
		$this->assertEquals($expected, $result);
442
	}
443
 
444
/**
445
 * testTranslatedFindList method
446
 *
447
 * @return void
448
 */
449
	public function testTranslatedFindList() {
450
		$this->loadFixtures('Translate', 'TranslatedItem');
451
 
452
		$TestModel = new TranslatedItem();
453
		$TestModel->locale = 'deu';
454
		$TestModel->displayField = 'title';
455
		$result = $TestModel->find('list', array('recursive' => 1));
456
		$expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3');
457
		$this->assertEquals($expected, $result);
458
 
459
		// SQL Server trigger an error and stops the page even if the debug = 0
460
		if ($this->db instanceof Sqlserver) {
461
			$debug = Configure::read('debug');
462
			Configure::write('debug', 0);
463
 
464
			$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
465
			$this->assertSame(array(), $result);
466
 
467
			$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
468
			$this->assertSame(array(), $result);
469
			Configure::write('debug', $debug);
470
		}
471
 
472
		$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before'));
473
		$expected = array(1 => null, 2 => null, 3 => null);
474
		$this->assertEquals($expected, $result);
475
	}
476
 
477
/**
478
 * testReadSelectedFields method
479
 *
480
 * @return void
481
 */
482
	public function testReadSelectedFields() {
483
		$this->loadFixtures('Translate', 'TranslatedItem');
484
 
485
		$TestModel = new TranslatedItem();
486
		$TestModel->locale = 'eng';
487
		$result = $TestModel->find('all', array('fields' => array('slug', 'TranslatedItem.content')));
488
		$expected = array(
489
			array('TranslatedItem' => array('slug' => 'first_translated', 'locale' => 'eng', 'content' => 'Content #1')),
490
			array('TranslatedItem' => array('slug' => 'second_translated', 'locale' => 'eng', 'content' => 'Content #2')),
491
			array('TranslatedItem' => array('slug' => 'third_translated', 'locale' => 'eng', 'content' => 'Content #3'))
492
		);
493
		$this->assertEquals($expected, $result);
494
 
495
		$result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug', 'content')));
496
		$this->assertEquals($expected, $result);
497
 
498
		$TestModel->locale = array('eng', 'deu', 'cze');
499
		$delete = array(array('locale' => 'deu'), array('field' => 'content', 'locale' => 'eng'));
500
		$I18nModel = ClassRegistry::getObject('TranslateTestModel');
501
		$I18nModel->deleteAll(array('or' => $delete));
502
 
503
		$result = $TestModel->find('all', array('fields' => array('title', 'content')));
504
		$expected = array(
505
			array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #1', 'content' => 'Obsah #1')),
506
			array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #2', 'content' => 'Obsah #2')),
507
			array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #3', 'content' => 'Obsah #3'))
508
		);
509
		$this->assertEquals($expected, $result);
510
	}
511
 
512
/**
513
 * testSaveCreate method
514
 *
515
 * @return void
516
 */
517
	public function testSaveCreate() {
518
		$this->loadFixtures('Translate', 'TranslatedItem');
519
 
520
		$TestModel = new TranslatedItem();
521
		$TestModel->locale = 'spa';
522
		$data = array(
523
			'slug' => 'fourth_translated',
524
			'title' => 'Leyenda #4',
525
			'content' => 'Contenido #4',
526
			'translated_article_id' => 1,
527
		);
528
		$TestModel->create($data);
529
		$TestModel->save();
530
		$result = $TestModel->read();
531
		$expected = array('TranslatedItem' => array_merge($data, array('id' => $TestModel->id, 'locale' => 'spa')));
532
		$this->assertEquals($expected, $result);
533
	}
534
 
535
/**
536
 * test saving/deleting with an alias, uses the model name.
537
 *
538
 * @return void
539
 */
540
	public function testSaveDeleteIgnoreAlias() {
541
		$this->loadFixtures('Translate', 'TranslatedItem');
542
 
543
		$TestModel = new TranslatedItem(array('alias' => 'SomethingElse'));
544
		$TestModel->locale = 'spa';
545
		$data = array(
546
			'slug' => 'fourth_translated',
547
			'title' => 'Leyenda #4',
548
			'content' => 'Contenido #4',
549
			'translated_article_id' => 1,
550
		);
551
		$TestModel->create($data);
552
		$TestModel->save();
553
		$id = $TestModel->id;
554
		$result = $TestModel->read();
555
		$expected = array($TestModel->alias => array_merge($data, array('id' => $id, 'locale' => 'spa')));
556
		$this->assertEquals($expected, $result);
557
 
558
		$TestModel->delete($id);
559
		$result = $TestModel->translateModel()->find('count', array(
560
			'conditions' => array('foreign_key' => $id)
561
		));
562
		$this->assertEquals(0, $result);
563
	}
564
 
565
/**
566
 * test save multiple locales method
567
 *
568
 * @return void
569
 */
570
	public function testSaveMultipleLocales() {
571
		$this->loadFixtures('Translate', 'TranslatedItem');
572
 
573
		$TestModel = new TranslatedItem();
574
		$data = array(
575
			'slug' => 'fourth_translated',
576
			'title' => array(
577
				'eng' => 'Title #4',
578
				'spa' => 'Leyenda #4',
579
			),
580
			'content' => array(
581
				'eng' => 'Content #4',
582
				'spa' => 'Contenido #4',
583
			),
584
			'translated_article_id' => 1,
585
		);
586
		$TestModel->create();
587
		$TestModel->save($data);
588
 
589
		$translations = array('title' => 'Title', 'content' => 'Content');
590
		$TestModel->bindTranslation($translations, false);
591
		$TestModel->locale = array('eng', 'spa');
592
		$result = $TestModel->read();
593
 
594
		$this->assertCount(2, $result['Title']);
595
		$this->assertEquals($result['Title'][0]['locale'], 'eng');
596
		$this->assertEquals($result['Title'][0]['content'], 'Title #4');
597
		$this->assertEquals($result['Title'][1]['locale'], 'spa');
598
		$this->assertEquals($result['Title'][1]['content'], 'Leyenda #4');
599
 
600
		$this->assertCount(2, $result['Content']);
601
	}
602
 
603
/**
604
 * testSaveAssociatedCreate method
605
 *
606
 * @return void
607
 */
608
	public function testSaveAssociatedMultipleLocale() {
609
		$this->loadFixtures('Translate', 'TranslatedItem');
610
 
611
		$TestModel = new TranslatedItem();
612
		$data = array(
613
			'slug' => 'fourth_translated',
614
			'title' => array(
615
				'eng' => 'Title #4',
616
				'spa' => 'Leyenda #4',
617
			),
618
			'content' => array(
619
				'eng' => 'Content #4',
620
				'spa' => 'Contenido #4',
621
			),
622
			'translated_article_id' => 1,
623
		);
624
		$TestModel->create();
625
		$TestModel->saveAssociated($data);
626
 
627
		$translations = array('title' => 'Title', 'content' => 'Content');
628
		$TestModel->bindTranslation($translations, false);
629
		$TestModel->locale = array('eng', 'spa');
630
		$result = $TestModel->read();
631
		$this->assertCount(2, $result['Title']);
632
		$this->assertCount(2, $result['Content']);
633
	}
634
 
635
/**
636
 * Test that saving only some of the translated fields allows the record to be found again.
637
 *
638
 * @return void
639
 */
640
	public function testSavePartialFields() {
641
		$this->loadFixtures('Translate', 'TranslatedItem');
642
 
643
		$TestModel = new TranslatedItem();
644
		$TestModel->locale = 'spa';
645
		$data = array(
646
			'slug' => 'fourth_translated',
647
			'title' => 'Leyenda #4',
648
		);
649
		$TestModel->create($data);
650
		$TestModel->save();
651
		$result = $TestModel->read();
652
		$expected = array(
653
			'TranslatedItem' => array(
654
				'id' => $TestModel->id,
655
				'translated_article_id' => null,
656
				'locale' => 'spa',
657
				'content' => '',
658
			) + $data
659
		);
660
		$this->assertEquals($expected, $result);
661
	}
662
 
663
/**
664
 * Test that all fields are create with partial data + multiple locales.
665
 *
666
 * @return void
667
 */
668
	public function testSavePartialFieldMultipleLocales() {
669
		$this->loadFixtures('Translate', 'TranslatedItem');
670
 
671
		$TestModel = new TranslatedItem();
672
		$TestModel->locale = 'eng';
673
		$data = array(
674
			'slug' => 'fifth_translated',
675
			'title' => array('eng' => 'Title #5', 'spa' => 'Leyenda #5'),
676
		);
677
		$TestModel->create($data);
678
		$TestModel->save();
679
		$TestModel->unbindTranslation();
680
 
681
		$translations = array('title' => 'Title', 'content' => 'Content');
682
		$TestModel->bindTranslation($translations, false);
683
		$result = $TestModel->read(null, $TestModel->id);
684
		$expected = array(
685
			'TranslatedItem' => array(
686
				'id' => '4',
687
				'translated_article_id' => null,
688
				'slug' => 'fifth_translated',
689
				'locale' => 'eng',
690
				'title' => 'Title #5',
691
				'content' => ''
692
			),
693
			'Title' => array(
694
 
695
					'id' => '19',
696
					'locale' => 'eng',
697
					'model' => 'TranslatedItem',
698
					'foreign_key' => '4',
699
					'field' => 'title',
700
					'content' => 'Title #5'
701
				),
702
				1 => array(
703
					'id' => '20',
704
					'locale' => 'spa',
705
					'model' => 'TranslatedItem',
706
					'foreign_key' => '4',
707
					'field' => 'title',
708
					'content' => 'Leyenda #5'
709
				)
710
			),
711
			'Content' => array(
712
 
713
					'id' => '21',
714
					'locale' => 'eng',
715
					'model' => 'TranslatedItem',
716
					'foreign_key' => '4',
717
					'field' => 'content',
718
					'content' => ''
719
				),
720
				1 => array(
721
					'id' => '22',
722
					'locale' => 'spa',
723
					'model' => 'TranslatedItem',
724
					'foreign_key' => '4',
725
					'field' => 'content',
726
					'content' => ''
727
				)
728
			)
729
		);
730
		$this->assertEquals($expected, $result);
731
	}
732
 
733
/**
734
 * testSaveUpdate method
735
 *
736
 * @return void
737
 */
738
	public function testSaveUpdate() {
739
		$this->loadFixtures('Translate', 'TranslatedItem');
740
 
741
		$TestModel = new TranslatedItem();
742
		$TestModel->locale = 'spa';
743
		$oldData = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'translated_article_id' => 1);
744
		$TestModel->create($oldData);
745
		$TestModel->save();
746
		$id = $TestModel->id;
747
		$newData = array('id' => $id, 'content' => 'Contenido #4');
748
		$TestModel->create($newData);
749
		$TestModel->save();
750
		$result = $TestModel->read(null, $id);
751
		$expected = array('TranslatedItem' => array_merge($oldData, $newData, array('locale' => 'spa')));
752
		$this->assertEquals($expected, $result);
753
	}
754
 
755
/**
756
 * testMultipleCreate method
757
 *
758
 * @return void
759
 */
760
	public function testMultipleCreate() {
761
		$this->loadFixtures('Translate', 'TranslatedItem');
762
 
763
		$TestModel = new TranslatedItem();
764
		$TestModel->locale = 'deu';
765
		$data = array(
766
			'slug' => 'new_translated',
767
			'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
768
			'content' => array('eng' => 'New content', 'spa' => 'Nuevo contenido')
769
		);
770
		$TestModel->create($data);
771
		$TestModel->save();
772
 
773
		$TestModel->unbindTranslation();
774
		$translations = array('title' => 'Title', 'content' => 'Content');
775
		$TestModel->bindTranslation($translations, false);
776
		$TestModel->locale = array('eng', 'spa');
777
 
778
		$result = $TestModel->read();
779
		$expected = array(
780
			'TranslatedItem' => array(
781
				'id' => 4,
782
				'slug' => 'new_translated',
783
				'locale' => 'eng',
784
				'title' => 'New title',
785
				'content' => 'New content',
786
				'translated_article_id' => null,
787
			),
788
			'Title' => array(
789
				array('id' => 21, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'New title'),
790
				array('id' => 22, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'Nuevo leyenda')
791
			),
792
			'Content' => array(
793
				array('id' => 19, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'New content'),
794
				array('id' => 20, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'Nuevo contenido')
795
			)
796
		);
797
		$this->assertEquals($expected, $result);
798
	}
799
 
800
/**
801
 * testMultipleUpdate method
802
 *
803
 * @return void
804
 */
805
	public function testMultipleUpdate() {
806
		$this->loadFixtures('Translate', 'TranslatedItem');
807
 
808
		$TestModel = new TranslatedItem();
809
		$TestModel->locale = 'eng';
810
		$TestModel->validate['title'] = 'notEmpty';
811
		$data = array('TranslatedItem' => array(
812
			'id' => 1,
813
			'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
814
			'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
815
		));
816
		$TestModel->create();
817
		$TestModel->save($data);
818
 
819
		$TestModel->unbindTranslation();
820
		$translations = array('title' => 'Title', 'content' => 'Content');
821
		$TestModel->bindTranslation($translations, false);
822
		$result = $TestModel->read(null, 1);
823
		$expected = array(
824
			'TranslatedItem' => array(
825
				'id' => '1',
826
				'slug' => 'first_translated',
827
				'locale' => 'eng',
828
				'title' => 'New Title #1',
829
				'content' => 'New Content #1',
830
				'translated_article_id' => 1,
831
			),
832
			'Title' => array(
833
				array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'New Title #1'),
834
				array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Neue Titel #1'),
835
				array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Novy Titulek #1')
836
			),
837
			'Content' => array(
838
				array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'New Content #1'),
839
				array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Neue Inhalt #1'),
840
				array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Novy Obsah #1')
841
			)
842
		);
843
		$this->assertEquals($expected, $result);
844
 
845
		$TestModel->unbindTranslation($translations);
846
		$TestModel->bindTranslation(array('title', 'content'), false);
847
	}
848
 
849
/**
850
 * testMixedCreateUpdateWithArrayLocale method
851
 *
852
 * @return void
853
 */
854
	public function testMixedCreateUpdateWithArrayLocale() {
855
		$this->loadFixtures('Translate', 'TranslatedItem');
856
 
857
		$TestModel = new TranslatedItem();
858
		$TestModel->locale = array('cze', 'deu');
859
		$data = array('TranslatedItem' => array(
860
			'id' => 1,
861
			'title' => array('eng' => 'Updated Title #1', 'spa' => 'Nuevo leyenda #1'),
862
			'content' => 'Upraveny obsah #1'
863
		));
864
		$TestModel->create();
865
		$TestModel->save($data);
866
 
867
		$TestModel->unbindTranslation();
868
		$translations = array('title' => 'Title', 'content' => 'Content');
869
		$TestModel->bindTranslation($translations, false);
870
		$result = $TestModel->read(null, 1);
871
		$result['Title'] = Hash::sort($result['Title'], '{n}.id', 'asc');
872
		$result['Content'] = Hash::sort($result['Content'], '{n}.id', 'asc');
873
		$expected = array(
874
			'TranslatedItem' => array(
875
				'id' => 1,
876
				'slug' => 'first_translated',
877
				'locale' => 'cze',
878
				'title' => 'Titulek #1',
879
				'content' => 'Upraveny obsah #1',
880
				'translated_article_id' => 1,
881
			),
882
			'Title' => array(
883
				array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Updated Title #1'),
884
				array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
885
				array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'),
886
				array('id' => 19, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Nuevo leyenda #1')
887
			),
888
			'Content' => array(
889
				array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
890
				array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
891
				array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Upraveny obsah #1')
892
			)
893
		);
894
		$this->assertEquals($expected, $result);
895
	}
896
 
897
/**
898
 * Test that saveAll() works with hasMany associations that contain
899
 * translations.
900
 *
901
 * @return void
902
 */
903
	public function testSaveAllTranslatedAssociations() {
904
		$this->loadFixtures('Translate', 'TranslateArticle', 'TranslatedItem', 'TranslatedArticle', 'User');
905
		$Model = new TranslatedArticle();
906
		$Model->locale = 'eng';
907
 
908
		$data = array(
909
			'TranslatedArticle' => array(
910
				'id' => 4,
911
				'user_id' => 1,
912
				'published' => 'Y',
913
				'title' => 'Title (eng) #1',
914
				'body' => 'Body (eng) #1'
915
			),
916
			'TranslatedItem' => array(
917
				array(
918
					'slug' => '',
919
					'title' => 'Nuevo leyenda #1',
920
					'content' => 'Upraveny obsah #1'
921
				),
922
				array(
923
					'slug' => '',
924
					'title' => 'New Title #2',
925
					'content' => 'New Content #2'
926
				),
927
			)
928
		);
929
		$result = $Model->saveAll($data);
930
		$this->assertTrue($result);
931
 
932
		$result = $Model->TranslatedItem->find('all', array(
933
			'conditions' => array('translated_article_id' => $Model->id)
934
		));
935
		$this->assertCount(2, $result);
936
		$this->assertEquals($data['TranslatedItem'][0]['title'], $result[0]['TranslatedItem']['title']);
937
		$this->assertEquals($data['TranslatedItem'][1]['title'], $result[1]['TranslatedItem']['title']);
938
	}
939
 
940
/**
941
 * testValidation method
942
 *
943
 * @return void
944
 */
945
	public function testValidation() {
946
		Configure::write('Config.language', 'eng');
947
		$this->loadFixtures('Translate', 'TranslatedItem');
948
 
949
		$TestModel = new TranslatedItem();
950
		$TestModel->locale = 'eng';
951
		$TestModel->validate['title'] = '/Only this title/';
952
		$data = array(
953
			'TranslatedItem' => array(
954
				'id' => 1,
955
				'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
956
				'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
957
			)
958
		);
959
		$TestModel->create();
960
		$this->assertFalse($TestModel->save($data));
961
		$this->assertEquals(array('This field cannot be left blank'), $TestModel->validationErrors['title']);
962
 
963
		$TestModel->locale = 'eng';
964
		$TestModel->validate['title'] = '/Only this title/';
965
		$data = array('TranslatedItem' => array(
966
			'id' => 1,
967
			'title' => array('eng' => 'Only this title', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
968
			'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
969
		));
970
		$TestModel->create();
971
		$result = $TestModel->save($data);
972
		$this->assertFalse(empty($result));
973
	}
974
 
975
/**
976
 * testAttachDetach method
977
 *
978
 * @return void
979
 */
980
	public function testAttachDetach() {
981
		$this->loadFixtures('Translate', 'TranslatedItem');
982
 
983
		$TestModel = new TranslatedItem();
984
 
985
		$TestModel->unbindTranslation();
986
		$translations = array('title' => 'Title', 'content' => 'Content');
987
		$TestModel->bindTranslation($translations, false);
988
 
989
		$result = array_keys($TestModel->hasMany);
990
		$expected = array('Title', 'Content');
991
		$this->assertEquals($expected, $result);
992
 
993
		$TestModel->Behaviors->unload('Translate');
994
		$result = array_keys($TestModel->hasMany);
995
		$expected = array();
996
		$this->assertEquals($expected, $result);
997
 
998
		$result = isset($TestModel->Behaviors->Translate);
999
		$this->assertFalse($result);
1000
 
1001
		$result = isset($Behavior->settings[$TestModel->alias]);
1002
		$this->assertFalse($result);
1003
 
1004
		$result = isset($Behavior->runtime[$TestModel->alias]);
1005
		$this->assertFalse($result);
1006
 
1007
		$TestModel->Behaviors->load('Translate', array('title' => 'Title', 'content' => 'Content'));
1008
		$result = array_keys($TestModel->hasMany);
1009
		$expected = array('Title', 'Content');
1010
		$this->assertEquals($expected, $result);
1011
 
1012
		$result = isset($TestModel->Behaviors->Translate);
1013
		$this->assertTrue($result);
1014
 
1015
		$Behavior = $TestModel->Behaviors->Translate;
1016
 
1017
		$result = isset($Behavior->settings[$TestModel->alias]);
1018
		$this->assertTrue($result);
1019
 
1020
		$result = isset($Behavior->runtime[$TestModel->alias]);
1021
		$this->assertTrue($result);
1022
	}
1023
 
1024
/**
1025
 * testAnotherTranslateTable method
1026
 *
1027
 * @return void
1028
 */
1029
	public function testAnotherTranslateTable() {
1030
		$this->loadFixtures('Translate', 'TranslatedItem', 'TranslateTable');
1031
 
1032
		$TestModel = new TranslatedItemWithTable();
1033
		$TestModel->locale = 'eng';
1034
		$result = $TestModel->read(null, 1);
1035
		$expected = array(
1036
			'TranslatedItemWithTable' => array(
1037
				'id' => 1,
1038
				'slug' => 'first_translated',
1039
				'locale' => 'eng',
1040
				'title' => 'Another Title #1',
1041
				'content' => 'Another Content #1',
1042
				'translated_article_id' => 1,
1043
			)
1044
		);
1045
		$this->assertEquals($expected, $result);
1046
	}
1047
 
1048
/**
1049
 * testTranslateWithAssociations method
1050
 *
1051
 * @return void
1052
 */
1053
	public function testTranslateWithAssociations() {
1054
		$this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'TranslatedItem', 'User', 'Comment', 'ArticlesTag', 'Tag');
1055
 
1056
		$TestModel = new TranslatedArticle();
1057
		$TestModel->locale = 'eng';
1058
		$recursive = $TestModel->recursive;
1059
 
1060
		$result = $TestModel->read(null, 1);
1061
		$expected = array(
1062
			'TranslatedArticle' => array(
1063
				'id' => 1,
1064
				'user_id' => 1,
1065
				'published' => 'Y',
1066
				'created' => '2007-03-18 10:39:23',
1067
				'updated' => '2007-03-18 10:41:31',
1068
				'locale' => 'eng',
1069
				'title' => 'Title (eng) #1',
1070
				'body' => 'Body (eng) #1'
1071
			),
1072
			'User' => array(
1073
				'id' => 1,
1074
				'user' => 'mariano',
1075
				'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
1076
				'created' => '2007-03-17 01:16:23',
1077
				'updated' => '2007-03-17 01:18:31'
1078
			),
1079
			'TranslatedItem' => array(
1080
				array(
1081
					'id' => 1,
1082
					'translated_article_id' => 1,
1083
					'slug' => 'first_translated'
1084
				),
1085
				array(
1086
					'id' => 2,
1087
					'translated_article_id' => 1,
1088
					'slug' => 'second_translated'
1089
				),
1090
				array(
1091
					'id' => 3,
1092
					'translated_article_id' => 1,
1093
					'slug' => 'third_translated'
1094
				),
1095
			)
1096
		);
1097
		$this->assertEquals($expected, $result);
1098
 
1099
		$result = $TestModel->find('all', array('recursive' => -1));
1100
		$expected = array(
1101
			array(
1102
				'TranslatedArticle' => array(
1103
					'id' => 1,
1104
					'user_id' => 1,
1105
					'published' => 'Y',
1106
					'created' => '2007-03-18 10:39:23',
1107
					'updated' => '2007-03-18 10:41:31',
1108
					'locale' => 'eng',
1109
					'title' => 'Title (eng) #1',
1110
					'body' => 'Body (eng) #1'
1111
				)
1112
			),
1113
			array(
1114
				'TranslatedArticle' => array(
1115
					'id' => 2,
1116
					'user_id' => 3,
1117
					'published' => 'Y',
1118
					'created' => '2007-03-18 10:41:23',
1119
					'updated' => '2007-03-18 10:43:31',
1120
					'locale' => 'eng',
1121
					'title' => 'Title (eng) #2',
1122
					'body' => 'Body (eng) #2'
1123
				)
1124
			),
1125
			array(
1126
				'TranslatedArticle' => array(
1127
					'id' => 3,
1128
					'user_id' => 1,
1129
					'published' => 'Y',
1130
					'created' => '2007-03-18 10:43:23',
1131
					'updated' => '2007-03-18 10:45:31',
1132
					'locale' => 'eng',
1133
					'title' => 'Title (eng) #3',
1134
					'body' => 'Body (eng) #3'
1135
				)
1136
			)
1137
		);
1138
		$this->assertEquals($expected, $result);
1139
		$this->assertEquals($TestModel->recursive, $recursive);
1140
 
1141
		$TestModel->recursive = -1;
1142
		$result = $TestModel->read(null, 1);
1143
		$expected = array(
1144
			'TranslatedArticle' => array(
1145
				'id' => 1,
1146
				'user_id' => 1,
1147
				'published' => 'Y',
1148
				'created' => '2007-03-18 10:39:23',
1149
				'updated' => '2007-03-18 10:41:31',
1150
				'locale' => 'eng',
1151
				'title' => 'Title (eng) #1',
1152
				'body' => 'Body (eng) #1'
1153
			)
1154
		);
1155
		$this->assertEquals($expected, $result);
1156
	}
1157
 
1158
/**
1159
 * testTranslateTableWithPrefix method
1160
 * Tests that is possible to have a translation model with a custom tablePrefix
1161
 *
1162
 * @return void
1163
 */
1164
	public function testTranslateTableWithPrefix() {
1165
		$this->loadFixtures('TranslateWithPrefix', 'TranslatedItem');
1166
		$TestModel = new TranslatedItem2;
1167
		$TestModel->locale = 'eng';
1168
		$result = $TestModel->read(null, 1);
1169
		$expected = array('TranslatedItem' => array(
1170
			'id' => 1,
1171
			'slug' => 'first_translated',
1172
			'locale' => 'eng',
1173
			'content' => 'Content #1',
1174
			'title' => 'Title #1',
1175
			'translated_article_id' => 1,
1176
		));
1177
		$this->assertEquals($expected, $result);
1178
	}
1179
 
1180
/**
1181
 * Test infinite loops not occurring with unbindTranslation()
1182
 *
1183
 * @return void
1184
 */
1185
	public function testUnbindTranslationInfinteLoop() {
1186
		$this->loadFixtures('Translate', 'TranslatedItem');
1187
 
1188
		$TestModel = new TranslatedItem();
1189
		$TestModel->Behaviors->unload('Translate');
1190
		$TestModel->actsAs = array();
1191
		$TestModel->Behaviors->load('Translate');
1192
		$TestModel->bindTranslation(array('title', 'content'), true);
1193
		$result = $TestModel->unbindTranslation();
1194
 
1195
		$this->assertFalse($result);
1196
	}
1197
 
1198
/**
1199
 * Test that an exception is raised when you try to over-write the name attribute.
1200
 *
1201
 * @expectedException CakeException
1202
 * @return void
1203
 */
1204
	public function testExceptionOnNameTranslation() {
1205
		$this->loadFixtures('Translate', 'TranslatedItem');
1206
		$TestModel = new TranslatedItem();
1207
		$TestModel->bindTranslation(array('name' => 'name'));
1208
	}
1209
 
1210
/**
1211
 * Test that translations can be bound and unbound dynamically.
1212
 *
1213
 * @return void
1214
 */
1215
	public function testUnbindTranslation() {
1216
		$this->loadFixtures('Translate', 'TranslatedItem');
1217
		$Model = new TranslatedItem();
1218
		$Model->unbindTranslation();
1219
		$Model->bindTranslation(array('body', 'slug'), false);
1220
 
1221
		$result = $Model->Behaviors->Translate->settings['TranslatedItem'];
1222
		$this->assertEquals(array('body', 'slug'), $result);
1223
 
1224
		$Model->unbindTranslation(array('body'));
1225
		$result = $Model->Behaviors->Translate->settings['TranslatedItem'];
1226
		$this->assertNotContains('body', $result);
1227
 
1228
		$Model->unbindTranslation('slug');
1229
		$result = $Model->Behaviors->Translate->settings['TranslatedItem'];
1230
		$this->assertNotContains('slug', $result);
1231
	}
1232
 
1233
/**
1234
 * Test that additional records are not inserted for associated translations.
1235
 *
1236
 * @return void
1237
 */
1238
	public function testNoExtraRowsForAssociatedTranslations() {
1239
		$this->loadFixtures('Translate', 'TranslatedItem');
1240
		$TestModel = new TranslatedItem();
1241
		$TestModel->locale = 'spa';
1242
		$TestModel->unbindTranslation();
1243
		$TestModel->bindTranslation(array('name' => 'nameTranslate'));
1244
 
1245
		$data = array(
1246
			'TranslatedItem' => array(
1247
				'slug' => 'spanish-name',
1248
				'name' => 'Spanish name',
1249
			),
1250
		);
1251
		$TestModel->create($data);
1252
		$TestModel->save();
1253
 
1254
		$Translate = $TestModel->translateModel();
1255
		$results = $Translate->find('all', array(
1256
			'conditions' => array(
1257
				'locale' => $TestModel->locale,
1258
				'foreign_key' => $TestModel->id
1259
			)
1260
		));
1261
		$this->assertCount(1, $results, 'Only one field should be saved');
1262
		$this->assertEquals('name', $results[0]['TranslateTestModel']['field']);
1263
	}
1264
 
1265
}