2011-03-22 09:50:26 +01:00
|
|
|
<?php
|
2011-03-22 22:15:15 +01:00
|
|
|
/**
|
|
|
|
* @package translatable
|
|
|
|
*/
|
2011-03-22 09:50:26 +01:00
|
|
|
class TranslatableSiteConfigTest extends SapphireTest {
|
|
|
|
|
2013-03-26 01:00:18 +01:00
|
|
|
protected static $fixture_file = 'translatable/tests/unit/TranslatableSiteConfigTest.yml';
|
2011-03-22 09:50:26 +01:00
|
|
|
|
|
|
|
protected $requiredExtensions = array(
|
|
|
|
'SiteTree' => array('Translatable'),
|
|
|
|
'SiteConfig' => array('Translatable'),
|
|
|
|
);
|
|
|
|
|
|
|
|
protected $illegalExtensions = array(
|
|
|
|
'SiteTree' => array('SiteTreeSubsites')
|
|
|
|
);
|
|
|
|
|
|
|
|
private $origLocale;
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->origLocale = Translatable::default_locale();
|
|
|
|
Translatable::set_default_locale("en_US");
|
2019-07-23 15:38:42 +02:00
|
|
|
|
|
|
|
// Delete any default records created outside of fixtures
|
|
|
|
SiteConfig::get()->exclude('ID', $this->allFixtureIDs('SiteConfig'))->removeAll();
|
2011-03-22 09:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
Translatable::set_default_locale($this->origLocale);
|
|
|
|
Translatable::set_current_locale($this->origLocale);
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCurrentCreatesDefaultForLocale() {
|
2012-08-16 04:11:25 +02:00
|
|
|
Translatable::set_current_locale(Translatable::default_locale());
|
2011-03-22 09:50:26 +01:00
|
|
|
$configEn = SiteConfig::current_site_config();
|
2012-08-16 04:11:25 +02:00
|
|
|
Translatable::set_current_locale('fr_FR');
|
|
|
|
$configFr = SiteConfig::current_site_config();
|
|
|
|
Translatable::set_current_locale(Translatable::default_locale());
|
2011-03-22 09:50:26 +01:00
|
|
|
|
2012-05-15 17:50:04 +02:00
|
|
|
$this->assertInstanceOf('SiteConfig', $configFr);
|
2011-03-22 09:50:26 +01:00
|
|
|
$this->assertEquals($configFr->Locale, 'fr_FR');
|
|
|
|
$this->assertEquals($configFr->Title, $configEn->Title, 'Copies title from existing config');
|
2012-10-02 22:29:56 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$configFr->getTranslationGroup(),
|
|
|
|
$configEn->getTranslationGroup(),
|
|
|
|
'Created in the same translation group'
|
|
|
|
);
|
2011-03-22 09:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testCanEditTranslatedRootPages() {
|
|
|
|
$configEn = $this->objFromFixture('SiteConfig', 'en_US');
|
|
|
|
$configDe = $this->objFromFixture('SiteConfig', 'de_DE');
|
|
|
|
|
|
|
|
$pageEn = $this->objFromFixture('Page', 'root_en');
|
|
|
|
$pageDe = $pageEn->createTranslation('de_DE');
|
|
|
|
|
|
|
|
$translatorDe = $this->objFromFixture('Member', 'translator_de');
|
|
|
|
$translatorEn = $this->objFromFixture('Member', 'translator_en');
|
|
|
|
|
|
|
|
$this->assertFalse($pageEn->canEdit($translatorDe));
|
|
|
|
$this->assertTrue($pageEn->canEdit($translatorEn));
|
|
|
|
}
|
|
|
|
}
|