2011-11-26 14:34:11 +01:00
|
|
|
<?php
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2016-07-19 04:09:15 +02:00
|
|
|
use SilverStripe\View\ThemeResourceLoader;
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
/**
|
2012-06-20 23:59:16 +02:00
|
|
|
* @package framework
|
2011-11-26 14:34:11 +01:00
|
|
|
* @subpackage i18n
|
|
|
|
*/
|
|
|
|
class i18nSSLegacyAdapterTest extends SapphireTest {
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
2011-11-26 14:34:11 +01:00
|
|
|
parent::setUp();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
|
|
|
|
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
|
2014-02-16 12:12:03 +01:00
|
|
|
Filesystem::makeFolder($this->alternateBaseSavePath);
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('Director', 'alternate_base_folder', $this->alternateBasePath);
|
2011-11-26 14:34:11 +01:00
|
|
|
|
2016-07-13 14:36:52 +02:00
|
|
|
// Replace old template loader with new one with alternate base path
|
2016-07-19 04:09:15 +02:00
|
|
|
$this->_oldLoader = ThemeResourceLoader::instance();
|
|
|
|
ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath));
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
$this->_oldTheme = Config::inst()->get('SSViewer', 'theme');
|
|
|
|
Config::inst()->update('SSViewer', 'theme', 'testtheme1');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-10-24 06:22:16 +02:00
|
|
|
$classManifest = new SS_ClassManifest($this->alternateBasePath, false, true, false);
|
2011-11-26 14:34:11 +01:00
|
|
|
SS_ClassLoader::instance()->pushManifest($classManifest);
|
|
|
|
|
|
|
|
$this->originalLocale = i18n::get_locale();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
// Override default adapter to avoid cached translations between tests.
|
|
|
|
// Emulates behaviour in i18n::get_translators()
|
|
|
|
$this->origAdapter = i18n::get_translator('core');
|
|
|
|
$adapter = new Zend_Translate(array(
|
2012-04-15 16:46:30 +02:00
|
|
|
'adapter' => 'i18nSSLegacyAdapter',
|
2011-11-26 14:34:11 +01:00
|
|
|
'locale' => i18n::default_locale(),
|
|
|
|
'disableNotices' => true,
|
|
|
|
));
|
|
|
|
i18n::register_translator($adapter, 'core');
|
|
|
|
$adapter->removeCache();
|
|
|
|
i18n::include_by_locale('en');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function tearDown() {
|
2016-07-19 04:09:15 +02:00
|
|
|
ThemeResourceLoader::set_instance($this->_oldLoader);
|
2011-11-26 14:34:11 +01:00
|
|
|
SS_ClassLoader::instance()->popManifest();
|
|
|
|
i18n::set_locale($this->originalLocale);
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('Director', 'alternate_base_folder', null);
|
|
|
|
Config::inst()->update('SSViewer', 'theme', $this->_oldTheme);
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::register_translator($this->origAdapter, 'core');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-11-26 14:34:11 +01:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTranslate() {
|
2011-11-26 14:34:11 +01:00
|
|
|
i18n::set_locale('en_US');
|
|
|
|
$this->assertEquals(
|
|
|
|
'Legacy translation',
|
|
|
|
// defined in i18nothermodule/lang/en_US.php
|
|
|
|
i18n::_t('i18nOtherModule.LEGACY'),
|
|
|
|
'Finds original strings in PHP module files'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'Legacy translation',
|
|
|
|
// defined in themes/testtheme1/lang/en_US.php
|
|
|
|
i18n::_t('i18nOtherModule.LEGACYTHEME'),
|
|
|
|
'Finds original strings in theme files'
|
|
|
|
);
|
|
|
|
i18n::set_locale('de_DE');
|
|
|
|
$this->assertEquals(
|
|
|
|
'Legacy translation (de_DE)',
|
|
|
|
// defined in i18nothermodule/lang/de_DE.php
|
|
|
|
i18n::_t('i18nOtherModule.LEGACY'),
|
|
|
|
'Finds translations in PHP module files'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'Legacy translation (de_DE)',
|
|
|
|
// defined in themes/testtheme1/lang/de_DE.php
|
|
|
|
i18n::_t('i18nOtherModule.LEGACYTHEME'),
|
|
|
|
'Finds original strings in theme files'
|
|
|
|
);
|
|
|
|
// TODO Implement likely subtags solution
|
|
|
|
// i18n::set_locale('de');
|
|
|
|
// $this->assertEquals(
|
|
|
|
// 'Legacy translation (de_DE)',
|
|
|
|
// // defined in i18nothermodule/lang/de_DE.php
|
|
|
|
// i18n::_t('i18nOtherModule.LEGACY'),
|
|
|
|
// 'Finds translations in PHP module files if only language locale is set'
|
|
|
|
// );
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-10-24 06:22:16 +02:00
|
|
|
}
|