2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.model.behaviors
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5669
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|
|
|
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
|
|
|
}
|
2008-11-03 23:58:44 +00:00
|
|
|
|
|
|
|
App::import('Core', array('AppModel', 'Model'));
|
|
|
|
require_once(dirname(dirname(__FILE__)) . DS . 'models.php');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-11-03 23:58:44 +00:00
|
|
|
* TranslateTest class.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.model.behaviors
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-11-03 23:58:44 +00:00
|
|
|
class TranslateTest extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-11-03 23:58:44 +00:00
|
|
|
* autoFixtures property
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-11-03 23:58:44 +00:00
|
|
|
var $autoFixtures = false;
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-11-03 23:58:44 +00:00
|
|
|
var $fixtures = array(
|
|
|
|
'core.translated_item', 'core.translate', 'core.translate_table',
|
|
|
|
'core.translated_article', 'core.translate_article', 'core.user', 'core.comment', 'core.tag', 'core.articles_tag'
|
|
|
|
);
|
2008-11-04 01:35:09 +00:00
|
|
|
/**
|
|
|
|
* endTest method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function endTest() {
|
|
|
|
ClassRegistry::flush();
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLocaleFalsePlain method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLocaleFalsePlain() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->read(null, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('all', array('fields' => array('slug')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array('TranslatedItem' => array('slug' => 'first_translated')),
|
|
|
|
array('TranslatedItem' => array('slug' => 'second_translated')),
|
|
|
|
array('TranslatedItem' => array('slug' => 'third_translated'))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLocaleFalseAssociations method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLocaleFalseAssociations() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = false;
|
|
|
|
$TestModel->unbindTranslation();
|
2008-05-30 11:40:08 +00:00
|
|
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->bindTranslation($translations, false);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->read(null, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'),
|
|
|
|
'Title' => array(
|
|
|
|
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
|
|
|
|
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
|
|
|
|
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1')
|
|
|
|
),
|
|
|
|
'Content' => array(
|
|
|
|
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
|
|
|
|
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
|
|
|
|
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1')
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content');
|
|
|
|
$TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng';
|
|
|
|
|
|
|
|
$result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array(
|
|
|
|
'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated'),
|
|
|
|
'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')),
|
|
|
|
'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array('id' => 2, 'slug' => 'second_translated'),
|
|
|
|
'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')),
|
|
|
|
'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array('id' => 3, 'slug' => 'third_translated'),
|
|
|
|
'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')),
|
|
|
|
'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3'))
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLocaleSingle method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLocaleSingle() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$result = $TestModel->read(null, 1);
|
|
|
|
$expected = array(
|
|
|
|
'TranslatedItem' => array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #1',
|
2008-11-03 23:58:44 +00:00
|
|
|
'content' => 'Content #1'
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('all');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #1',
|
|
|
|
'content' => 'Content #1'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 2,
|
|
|
|
'slug' => 'second_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #2',
|
|
|
|
'content' => 'Content #2'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 3,
|
|
|
|
'slug' => 'third_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #3',
|
|
|
|
'content' => 'Content #3'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLocaleSingleWithConditions method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLocaleSingleWithConditions() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #1',
|
|
|
|
'content' => 'Content #1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('all', array('conditions' => "TranslatedItem.slug = 'first_translated'"));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #1',
|
|
|
|
'content' => 'Content #1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLocaleSingleAssociations method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLocaleSingleAssociations() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$TestModel->unbindTranslation();
|
2008-05-30 11:40:08 +00:00
|
|
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->bindTranslation($translations, false);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->read(null, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title #1',
|
|
|
|
'content' => 'Content #1'
|
|
|
|
),
|
|
|
|
'Title' => array(
|
|
|
|
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Title #1'),
|
|
|
|
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
|
|
|
|
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1')
|
|
|
|
),
|
|
|
|
'Content' => array(
|
|
|
|
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
|
|
|
|
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
|
|
|
|
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Obsah #1')
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->hasMany['Title']['fields'] = $TestModel->hasMany['Content']['fields'] = array('content');
|
|
|
|
$TestModel->hasMany['Title']['conditions']['locale'] = $TestModel->hasMany['Content']['conditions']['locale'] = 'eng';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('all', array('fields' => array('TranslatedItem.title')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array(
|
|
|
|
'TranslatedItem' => array('id' => 1, 'locale' => 'eng', 'title' => 'Title #1'),
|
|
|
|
'Title' => array(array('foreign_key' => 1, 'content' => 'Title #1')),
|
|
|
|
'Content' => array(array('foreign_key' => 1, 'content' => 'Content #1'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array('id' => 2, 'locale' => 'eng', 'title' => 'Title #2'),
|
|
|
|
'Title' => array(array('foreign_key' => 2, 'content' => 'Title #2')),
|
|
|
|
'Content' => array(array('foreign_key' => 2, 'content' => 'Content #2'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array('id' => 3, 'locale' => 'eng', 'title' => 'Title #3'),
|
|
|
|
'Title' => array(array('foreign_key' => 3, 'content' => 'Title #3')),
|
|
|
|
'Content' => array(array('foreign_key' => 3, 'content' => 'Content #3'))
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLocaleMultiple method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLocaleMultiple() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = array('deu', 'eng', 'cze');
|
2008-05-30 11:40:08 +00:00
|
|
|
$delete = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array('locale' => 'deu'),
|
|
|
|
array('foreign_key' => 1, 'field' => 'title', 'locale' => 'eng'),
|
|
|
|
array('foreign_key' => 1, 'field' => 'content', 'locale' => 'cze'),
|
|
|
|
array('foreign_key' => 2, 'field' => 'title', 'locale' => 'cze'),
|
|
|
|
array('foreign_key' => 2, 'field' => 'content', 'locale' => 'eng'),
|
|
|
|
array('foreign_key' => 3, 'field' => 'title')
|
|
|
|
);
|
|
|
|
$I18nModel =& ClassRegistry::getObject('TranslateTestModel');
|
|
|
|
$I18nModel->deleteAll(array('or' => $delete));
|
|
|
|
|
|
|
|
$result = $TestModel->read(null, 1);
|
|
|
|
$expected = array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'deu',
|
|
|
|
'title' => 'Titulek #1',
|
|
|
|
'content' => 'Content #1'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $TestModel->find('all', array('fields' => array('slug', 'title', 'content')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'deu',
|
|
|
|
'title' => 'Titulek #1',
|
|
|
|
'content' => 'Content #1'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'TranslatedItem' => array(
|
2008-11-03 23:58:44 +00:00
|
|
|
'slug' => 'second_translated',
|
|
|
|
'locale' => 'deu',
|
|
|
|
'title' => 'Title #2',
|
|
|
|
'content' => 'Obsah #2'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'TranslatedItem' => array(
|
|
|
|
'slug' => 'third_translated',
|
|
|
|
'locale' => 'deu',
|
|
|
|
'title' => '',
|
|
|
|
'content' => 'Content #3'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-11-03 23:58:44 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testMissingTranslation method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMissingTranslation() {
|
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'rus';
|
|
|
|
$result = $TestModel->read(null, 1);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$TestModel->locale = array('rus');
|
|
|
|
$result = $TestModel->read(null, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
'TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'rus',
|
|
|
|
'title' => '',
|
|
|
|
'content' => ''
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testTranslatedFindList method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testTranslatedFindList() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'deu';
|
|
|
|
$TestModel->displayField = 'title';
|
|
|
|
$result = $TestModel->find('list', array('recursive' => 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3');
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-09-04 02:04:44 +00:00
|
|
|
|
|
|
|
$debug = Configure::read('debug');
|
|
|
|
Configure::write('debug', 0);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
|
2008-09-04 02:04:44 +00:00
|
|
|
$this->assertEqual($result, array());
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
|
2008-09-04 02:04:44 +00:00
|
|
|
$this->assertEqual($result, array());
|
|
|
|
Configure::write('debug', $debug);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before'));
|
2008-09-04 02:04:44 +00:00
|
|
|
$expected = array(1 => null, 2 => null, 3 => null);
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testReadSelectedFields method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testReadSelectedFields() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$result = $TestModel->find('all', array('fields' => array('slug', 'TranslatedItem.content')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array('TranslatedItem' => array('slug' => 'first_translated', 'locale' => 'eng', 'content' => 'Content #1')),
|
|
|
|
array('TranslatedItem' => array('slug' => 'second_translated', 'locale' => 'eng', 'content' => 'Content #2')),
|
|
|
|
array('TranslatedItem' => array('slug' => 'third_translated', 'locale' => 'eng', 'content' => 'Content #3'))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('all', array('fields' => array('TranslatedItem.slug', 'content')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->locale = array('eng', 'deu', 'cze');
|
2008-05-30 11:40:08 +00:00
|
|
|
$delete = array(array('locale' => 'deu'), array('field' => 'content', 'locale' => 'eng'));
|
2008-11-03 23:58:44 +00:00
|
|
|
$I18nModel =& ClassRegistry::getObject('TranslateTestModel');
|
|
|
|
$I18nModel->deleteAll(array('or' => $delete));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->find('all', array('fields' => array('title', 'content')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #1', 'content' => 'Obsah #1')),
|
|
|
|
array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #2', 'content' => 'Obsah #2')),
|
|
|
|
array('TranslatedItem' => array('locale' => 'eng', 'title' => 'Title #3', 'content' => 'Obsah #3'))
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSaveCreate method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSaveCreate() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'spa';
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4', 'content' => 'Contenido #4');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create($data);
|
|
|
|
$TestModel->save();
|
|
|
|
$result = $TestModel->read();
|
|
|
|
$expected = array('TranslatedItem' => array_merge($data, array('id' => $TestModel->id, 'locale' => 'spa')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSaveUpdate method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSaveUpdate() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'spa';
|
2008-05-30 11:40:08 +00:00
|
|
|
$oldData = array('slug' => 'fourth_translated', 'title' => 'Leyenda #4');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create($oldData);
|
|
|
|
$TestModel->save();
|
|
|
|
$id = $TestModel->id;
|
2008-05-30 11:40:08 +00:00
|
|
|
$newData = array('id' => $id, 'content' => 'Contenido #4');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create($newData);
|
|
|
|
$TestModel->save();
|
|
|
|
$result = $TestModel->read(null, $id);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('TranslatedItem' => array_merge($oldData, $newData, array('locale' => 'spa')));
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMultipleCreate method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMultipleCreate() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'deu';
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = array(
|
|
|
|
'slug' => 'new_translated',
|
|
|
|
'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'),
|
|
|
|
'content' => array('eng' => 'New content', 'spa' => 'Nuevo contenido')
|
|
|
|
);
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create($data);
|
|
|
|
$TestModel->save();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->unbindTranslation();
|
2008-05-30 11:40:08 +00:00
|
|
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->bindTranslation($translations, false);
|
|
|
|
$TestModel->locale = array('eng', 'spa');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = $TestModel->read();
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'TranslatedItem' => array('id' => 4, 'slug' => 'new_translated', 'locale' => 'eng', 'title' => 'New title', 'content' => 'New content'),
|
|
|
|
'Title' => array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array('id' => 21, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'New title'),
|
|
|
|
array('id' => 22, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'title', 'content' => 'Nuevo leyenda')
|
2008-05-30 11:40:08 +00:00
|
|
|
),
|
|
|
|
'Content' => array(
|
2008-11-03 23:58:44 +00:00
|
|
|
array('id' => 19, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'New content'),
|
|
|
|
array('id' => 20, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 4, 'field' => 'content', 'content' => 'Nuevo contenido')
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMultipleUpdate method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMultipleUpdate() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$TestModel->validate['title'] = VALID_NOT_EMPTY;
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = array('TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
|
|
|
|
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
|
|
|
|
));
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create();
|
|
|
|
$TestModel->save($data);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->unbindTranslation();
|
2008-05-30 11:40:08 +00:00
|
|
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->bindTranslation($translations, false);
|
|
|
|
$result = $TestModel->read(null, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'TranslatedItem' => array('id' => '1', 'slug' => 'first_translated', 'locale' => 'eng', 'title' => 'New Title #1', 'content' => 'New Content #1'),
|
|
|
|
'Title' => array(
|
|
|
|
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'New Title #1'),
|
|
|
|
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Neue Titel #1'),
|
|
|
|
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Novy Titulek #1')
|
|
|
|
),
|
|
|
|
'Content' => array(
|
|
|
|
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'New Content #1'),
|
|
|
|
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Neue Inhalt #1'),
|
|
|
|
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Novy Obsah #1')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->unbindTranslation($translations);
|
|
|
|
$TestModel->bindTranslation(array('title', 'content'), false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMixedCreateUpdateWithArrayLocale method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMixedCreateUpdateWithArrayLocale() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = array('cze', 'deu');
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = array('TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'title' => array('eng' => 'Updated Title #1', 'spa' => 'Nuevo leyenda #1'),
|
|
|
|
'content' => 'Upraveny obsah #1'
|
|
|
|
));
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create();
|
|
|
|
$TestModel->save($data);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->unbindTranslation();
|
2008-05-30 11:40:08 +00:00
|
|
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->bindTranslation($translations, false);
|
|
|
|
$result = $TestModel->read(null, 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'TranslatedItem' => array('id' => 1, 'slug' => 'first_translated', 'locale' => 'cze', 'title' => 'Titulek #1', 'content' => 'Upraveny obsah #1'),
|
|
|
|
'Title' => array(
|
|
|
|
array('id' => 1, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Updated Title #1'),
|
|
|
|
array('id' => 3, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titel #1'),
|
|
|
|
array('id' => 5, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Titulek #1'),
|
|
|
|
array('id' => 19, 'locale' => 'spa', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'title', 'content' => 'Nuevo leyenda #1')
|
|
|
|
),
|
|
|
|
'Content' => array(
|
|
|
|
array('id' => 2, 'locale' => 'eng', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Content #1'),
|
|
|
|
array('id' => 4, 'locale' => 'deu', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Inhalt #1'),
|
|
|
|
array('id' => 6, 'locale' => 'cze', 'model' => 'TranslatedItem', 'foreign_key' => 1, 'field' => 'content', 'content' => 'Upraveny obsah #1')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2008-06-14 23:21:09 +00:00
|
|
|
/**
|
|
|
|
* testValidation method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testValidation() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$TestModel->validate['title'] = '/Only this title/';
|
2008-06-14 23:21:09 +00:00
|
|
|
$data = array('TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
|
|
|
|
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
|
|
|
|
));
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create();
|
|
|
|
$this->assertFalse($TestModel->save($data));
|
|
|
|
$this->assertEqual($TestModel->validationErrors['title'], 'This field cannot be left blank');
|
2008-06-14 23:21:09 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$TestModel->validate['title'] = '/Only this title/';
|
2008-06-14 23:21:09 +00:00
|
|
|
$data = array('TranslatedItem' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'title' => array('eng' => 'Only this title', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
|
|
|
|
'content' => array('eng' => 'New Content #1', 'deu' => 'Neue Inhalt #1', 'cze' => 'Novy Obsah #1')
|
|
|
|
));
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->create();
|
|
|
|
$this->assertTrue($TestModel->save($data));
|
2008-06-14 23:21:09 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testAttachDetach method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAttachDetach() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItem();
|
|
|
|
$Behavior = $TestModel->Behaviors->Translate;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->unbindTranslation();
|
2008-05-30 11:40:08 +00:00
|
|
|
$translations = array('title' => 'Title', 'content' => 'Content');
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->bindTranslation($translations, false);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = array_keys($TestModel->hasMany);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('Title', 'Content');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->Behaviors->detach('Translate');
|
|
|
|
$result = array_keys($TestModel->hasMany);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array();
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = isset($TestModel->Behaviors->Translate);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = isset($Behavior->settings[$TestModel->alias]);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = isset($Behavior->runtime[$TestModel->alias]);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$TestModel->Behaviors->attach('Translate', array('title' => 'Title', 'content' => 'Content'));
|
|
|
|
$result = array_keys($TestModel->hasMany);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array('Title', 'Content');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = isset($TestModel->Behaviors->Translate);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$Behavior = $TestModel->Behaviors->Translate;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = isset($Behavior->settings[$TestModel->alias]);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2008-11-03 23:58:44 +00:00
|
|
|
$result = isset($Behavior->runtime[$TestModel->alias]);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testAnotherTranslateTable method
|
2008-06-14 23:21:09 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAnotherTranslateTable() {
|
2008-11-03 23:58:44 +00:00
|
|
|
$this->loadFixtures('Translate', 'TranslatedItem', 'TranslateTable');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedItemWithTable();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$result = $TestModel->read(null, 1);
|
|
|
|
$expected = array(
|
|
|
|
'TranslatedItemWithTable' => array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'id' => 1,
|
|
|
|
'slug' => 'first_translated',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Another Title #1',
|
2008-11-03 23:58:44 +00:00
|
|
|
'content' => 'Another Content #1'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testTranslateWithAssociations method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testTranslateWithAssociations() {
|
|
|
|
$this->loadFixtures('TranslateArticle', 'TranslatedArticle', 'User', 'Comment', 'ArticlesTag', 'Tag');
|
|
|
|
|
|
|
|
$TestModel =& new TranslatedArticle();
|
|
|
|
$TestModel->locale = 'eng';
|
|
|
|
$result = $TestModel->read(null, 1);
|
|
|
|
$expected = array(
|
|
|
|
'TranslatedArticle' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'user_id' => 1,
|
|
|
|
'published' => 'Y',
|
|
|
|
'created' => '2007-03-18 10:39:23',
|
|
|
|
'updated' => '2007-03-18 10:41:31',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title (eng) #1',
|
|
|
|
'body' => 'Body (eng) #1'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'user' => 'mariano',
|
|
|
|
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23',
|
|
|
|
'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$TestModel->recursive = -1;
|
|
|
|
$result = $TestModel->read(null, 1);
|
|
|
|
$expected = array(
|
|
|
|
'TranslatedArticle' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'user_id' => 1,
|
|
|
|
'published' => 'Y',
|
|
|
|
'created' => '2007-03-18 10:39:23',
|
|
|
|
'updated' => '2007-03-18 10:41:31',
|
|
|
|
'locale' => 'eng',
|
|
|
|
'title' => 'Title (eng) #1',
|
|
|
|
'body' => 'Body (eng) #1'
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
}
|
2008-06-14 23:21:09 +00:00
|
|
|
?>
|