function testTranslationGroups() { // first in french $frPage = new SiteTree(); $frPage->Locale = 'fr_FR'; $frPage->write(); // second in english (from french "original") $enPage = $frPage->createTranslation('en_US'); // third in spanish (from the english translation) $esPage = $enPage->createTranslation('es_ES'); // test french $this->assertEquals($frPage->getTranslations()->column('Locale'), array('en_US', 'es_ES')); $this->assertNotNull($frPage->getTranslation('en_US')); $this->assertEquals($frPage->getTranslation('en_US')->ID, $enPage->ID); $this->assertNotNull($frPage->getTranslation('es_ES')); $this->assertEquals($frPage->getTranslation('es_ES')->ID, $esPage->ID); // test english $this->assertEquals($enPage->getTranslations()->column('Locale'), array('fr_FR', 'es_ES')); $this->assertNotNull($frPage->getTranslation('fr_FR')); $this->assertEquals($enPage->getTranslation('fr_FR')->ID, $frPage->ID); $this->assertNotNull($frPage->getTranslation('es_ES')); $this->assertEquals($enPage->getTranslation('es_ES')->ID, $esPage->ID); // test spanish $this->assertEquals($esPage->getTranslations()->column('Locale'), array('fr_FR', 'en_US')); $this->assertNotNull($esPage->getTranslation('fr_FR')); $this->assertEquals($esPage->getTranslation('fr_FR')->ID, $frPage->ID); $this->assertNotNull($esPage->getTranslation('en_US')); $this->assertEquals($esPage->getTranslation('en_US')->ID, $enPage->ID); }
function testTranslationGroupsWhenTranslationIsSubclass() { // create an English SiteTree $enST = new SiteTree(); $enST->Locale = 'en_US'; $enST->write(); // create French and Spanish translations $frST = $enST->createTranslation('fr_FR'); $esST = $enST->createTranslation('es_ES'); // test that we get the right translations back from each instance $this->assertArrayEqualsAfterSort(array('fr_FR', 'es_ES'), $enST->getTranslations()->column('Locale')); $this->assertArrayEqualsAfterSort(array('en_US', 'es_ES'), $frST->getTranslations()->column('Locale')); $this->assertArrayEqualsAfterSort(array('en_US', 'fr_FR'), $esST->getTranslations()->column('Locale')); // this should be considered an edge-case, but on some sites translations // may be allowed to be a subclass of the default locale's translation of // the same page. In this case, we need to support getTranslations returning // all of the translations, even if one of the translations is a different // class from others $esST->setClassName('Page'); $esST->write(); $esPg = DataObject::get_by_id('Page', $esST->ID, $cache = false); // make sure we successfully changed the class $this->assertClass('Page', $esPg); // and make sure that the class of the others did not change $frST = DataObject::get_by_id('SiteTree', $frST->ID, $cache = false); $this->assertClass('SiteTree', $frST); $enST = DataObject::get_by_id('SiteTree', $enST->ID, $cache = false); $this->assertClass('SiteTree', $enST); // now that we know our edge case is successfully configured, we need to // make sure that we get the right translations back from everything $this->assertArrayEqualsAfterSort(array('fr_FR', 'es_ES'), $enST->getTranslations()->column('Locale')); $this->assertArrayEqualsAfterSort(array('en_US', 'es_ES'), $frST->getTranslations()->column('Locale')); $this->assertArrayEqualsAfterSort(array('en_US', 'fr_FR'), $esPg->getTranslations()->column('Locale')); $this->assertEquals($enST->ID, $esPg->getTranslation('en_US')->ID); $this->assertEquals($frST->ID, $esPg->getTranslation('fr_FR')->ID); $this->assertEquals($esPg->ID, $enST->getTranslation('es_ES')->ID); $this->assertEquals($esPg->ID, $frST->getTranslation('es_ES')->ID); }