mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
1cdca8a66a
ENHANCEMENT Added Translatable_Transformation (patched in r64523) ENHANCEMENT Added TranslatableTest with minimal assertions about existing form fields in translation mode git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@66137 467b73ca-7a2a-4603-9d3b-597d59a354a9
70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class TranslatableTest extends FunctionalTest {
|
|
|
|
static $fixture_file = 'sapphire/tests/model/TranslatableTest.yml';
|
|
|
|
protected $recreateTempDb = true;
|
|
|
|
/**
|
|
* @todo Necessary because of monolithic Translatable design
|
|
*/
|
|
protected $origTranslatableSettings = array();
|
|
|
|
function setUp() {
|
|
$this->origTranslatableSettings['enabled'] = Translatable::is_enabled();
|
|
$this->origTranslatableSettings['default_lang'] = Translatable::default_lang();
|
|
Translatable::enable();
|
|
Translatable::set_default_lang("en");
|
|
|
|
// needs to recreate the database schema with *_lang tables
|
|
self::kill_temp_db();
|
|
self::create_temp_db();
|
|
|
|
parent::setUp();
|
|
}
|
|
|
|
function tearDown() {
|
|
if(!$this->origTranslatableSettings['enabled']) Translatable::disable();
|
|
Translatable::set_default_lang($this->origTranslatableSettings['default_lang']);
|
|
|
|
self::kill_temp_db();
|
|
self::create_temp_db();
|
|
}
|
|
|
|
function testUpdateCMSFieldsOnSiteTree() {
|
|
$pageOrigLang = $this->objFromFixture('SiteTree', 'home');
|
|
|
|
// first test with default language
|
|
$fields = $pageOrigLang->getCMSFields();
|
|
$this->assertType(
|
|
'TextField',
|
|
$fields->dataFieldByName('Title'),
|
|
'Translatable doesnt modify fields if called in default language (e.g. "non-translation mode")'
|
|
);
|
|
$this->assertNull(
|
|
$fields->dataFieldByName('Title_original'),
|
|
'Translatable doesnt modify fields if called in default language (e.g. "non-translation mode")'
|
|
);
|
|
|
|
// then in "translation mode"
|
|
$pageTranslated = Translatable::get_one_by_lang('SiteTree',"fr", "ID = $pageOrigLang->ID");
|
|
$fields = $pageTranslated->getCMSFields();
|
|
$this->assertType(
|
|
'TextField',
|
|
$fields->dataFieldByName('Title'),
|
|
'Translatable leaves original formfield intact in "translation mode"'
|
|
);
|
|
$readonlyField = $fields->dataFieldByName('Title')->performReadonlyTransformation();
|
|
$this->assertType(
|
|
$readonlyField->class,
|
|
$fields->dataFieldByName('Title_original'),
|
|
'Translatable adds the original value as a ReadonlyField in "translation mode"'
|
|
);
|
|
|
|
}
|
|
}
|
|
?>
|