mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added basic unit tests to new Translatable API
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@70073 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
00619a02f9
commit
080cd5c99f
@ -22,8 +22,11 @@ class TranslatableTest extends FunctionalTest {
|
||||
|
||||
// needs to recreate the database schema with *_lang tables
|
||||
self::kill_temp_db();
|
||||
// refresh the decorated statics - different fields in $db with Translatable enabled
|
||||
singleton('SiteTree')->loadExtraStatics();
|
||||
self::create_temp_db();
|
||||
$dbname = self::create_temp_db();
|
||||
DB::set_alternative_database_name($dbname);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
@ -38,12 +41,94 @@ class TranslatableTest extends FunctionalTest {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
function testCreateTranslation() {
|
||||
function testCreateTranslationOnSiteTree() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $origPage->createTranslation('de');
|
||||
|
||||
$this->assertEquals($translatedPage->Lang, 'de');
|
||||
$this->assertNotEquals($translatedPage->ID, $origPage->ID);
|
||||
$this->assertEquals($translatedPage->OriginalID, $origPage->ID);
|
||||
|
||||
$subsequentTranslatedPage = $origPage->createTranslation('de');
|
||||
$this->assertEquals(
|
||||
$translatedPage->ID,
|
||||
$subsequentTranslatedPage->ID,
|
||||
'Subsequent calls to createTranslation() dont cause new records in database'
|
||||
);
|
||||
}
|
||||
|
||||
function testGetOriginalPage() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $origPage->createTranslation('de');
|
||||
|
||||
$this->assertEquals($translatedPage->getOriginalPage()->ID, $origPage->ID);
|
||||
}
|
||||
|
||||
function testIsTranslation() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $origPage->createTranslation('de');
|
||||
|
||||
$this->assertFalse($origPage->isTranslation());
|
||||
$this->assertTrue($translatedPage->isTranslation());
|
||||
}
|
||||
|
||||
function testGetTranslationOnSiteTree() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $this->objFromFixture('Page', 'testpage_fr');
|
||||
|
||||
$getTranslationPage = $origPage->getTranslation('fr');
|
||||
$this->assertNotNull($getTranslationPage);
|
||||
$this->assertEquals($getTranslationPage->ID, $translatedPage->ID);
|
||||
}
|
||||
|
||||
function testGetTranslatedLanguages() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
// manual creation of page
|
||||
$translationDe = new Page();
|
||||
$translationDe->OriginalID = $origPage->ID;
|
||||
$translationDe->Lang = 'de';
|
||||
$translationDe->write();
|
||||
|
||||
// through createTranslation()
|
||||
$translationAf = $origPage->createTranslation('af');
|
||||
|
||||
// create a new language on an unrelated page which shouldnt be returned from $origPage
|
||||
$otherPage = new Page();
|
||||
$otherPage->write();
|
||||
$otherTranslationEs = $otherPage->createTranslation('es');
|
||||
|
||||
$this->assertEquals(
|
||||
$origPage->getTranslatedLangs(),
|
||||
array(
|
||||
'af',
|
||||
'de',
|
||||
//'en', // default language is not included
|
||||
'fr', // already in the fixtures
|
||||
),
|
||||
'Language codes are returned specifically for the queried page through getTranslatedLangs()'
|
||||
);
|
||||
|
||||
$pageWithoutTranslations = new Page();
|
||||
$pageWithoutTranslations->write();
|
||||
$this->assertEquals(
|
||||
$pageWithoutTranslations->getTranslatedLangs(),
|
||||
array(),
|
||||
'A page without translations returns empty array through getTranslatedLangs(), ' .
|
||||
'even if translations for other pages exist in the database'
|
||||
);
|
||||
}
|
||||
|
||||
function testTranslationCanHaveSameURLSegment() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $origPage->createTranslation('de');
|
||||
$translatedPage->URLSegment = 'testpage';
|
||||
$translatedPage->publish('Stage', 'Live');
|
||||
|
||||
$this->assertEquals($origPage->URLSegment, $translatedPage->URLSegment);
|
||||
}
|
||||
|
||||
function testUpdateCMSFieldsOnSiteTree() {
|
||||
$pageOrigLang = $this->objFromFixture('Page', 'home_en');
|
||||
$pageOrigLang = $this->objFromFixture('Page', 'testpage_en');
|
||||
|
||||
// first test with default language
|
||||
$fields = $pageOrigLang->getCMSFields();
|
||||
@ -58,7 +143,7 @@ class TranslatableTest extends FunctionalTest {
|
||||
);
|
||||
|
||||
// then in "translation mode"
|
||||
$pageTranslated = $this->objFromFixture('Page', 'home_fr');
|
||||
$pageTranslated = $this->objFromFixture('Page', 'testpage_fr');
|
||||
$fields = $pageTranslated->getCMSFields();
|
||||
$this->assertType(
|
||||
'TextField',
|
||||
|
@ -1,13 +1,13 @@
|
||||
Page:
|
||||
home_en:
|
||||
testpage_en:
|
||||
Title: Home
|
||||
URLSegment: home
|
||||
URLSegment: testpage
|
||||
Lang: en
|
||||
home_fr:
|
||||
testpage_fr:
|
||||
Title: Maison
|
||||
URLSegment: home
|
||||
URLSegment: testpage
|
||||
Lang: fr
|
||||
OriginalID: =>Page.home_en
|
||||
OriginalID: =>Page.testpage_en
|
||||
parent:
|
||||
Title: Parent
|
||||
URLSegment: parent
|
||||
|
Loading…
Reference in New Issue
Block a user