function setUp() {
		parent::setUp();
		
		$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
		$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
		FileSystem::makeFolder($this->alternateBaseSavePath);
		Director::setBaseFolder($this->alternateBasePath);

		// Push a template loader running from the fake webroot onto the stack.
		$templateManifest = new SS_TemplateManifest($this->alternateBasePath, false, true);
		$templateManifest->regenerate(false);
		SS_TemplateLoader::instance()->pushManifest($templateManifest);
		$this->_oldTheme = SSViewer::current_theme();
		SSViewer::set_theme('testtheme1');
		
		$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
		SS_ClassLoader::instance()->pushManifest($classManifest);

		$this->originalLocale = i18n::get_locale();
		
		// 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(
			'adapter' => 'i18nSSLegacyAdapter',
			'locale' => i18n::default_locale(),
			'disableNotices' => true,
		));
		i18n::register_translator($adapter, 'core');
		$adapter->removeCache();
		i18n::include_by_locale('en');
	}
 public function testUpdateFieldLabels()
 {
     // Add custom translation for testing
     i18n::get_translator('core')->getAdapter()->addTranslation(array('SiteTree.METATITLE' => 'TRANS-EN Meta Title'), 'en');
     $siteTree = new SiteTree();
     $labels = $siteTree->fieldLabels();
     $this->assertArrayHasKey('MetaTitle', $labels);
     $this->assertEquals('TRANS-EN Meta Title', $labels['MetaTitle']);
     // Set different locale, clear field label cache
     i18n::set_locale('de_DE');
     DataObject::reset();
     // Add custom translation for testing
     i18n::get_translator('core')->getAdapter()->addTranslation(array('SiteTree.METATITLE' => 'TRANS-DE Meta Title'), 'de_DE');
     $labels = $siteTree->fieldLabels();
     $this->assertEquals('TRANS-DE Meta Title', $labels['MetaTitle']);
 }
 public function setUp()
 {
     parent::setUp();
     $this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
     $this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
     Filesystem::makeFolder($this->alternateBaseSavePath);
     Config::inst()->update('Director', 'alternate_base_folder', $this->alternateBasePath);
     // Replace old template loader with new one with alternate base path
     $this->_oldLoader = ThemeResourceLoader::instance();
     ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath));
     $this->_oldTheme = Config::inst()->get('SSViewer', 'theme');
     Config::inst()->update('SSViewer', 'theme', 'testtheme1');
     $classManifest = new SS_ClassManifest($this->alternateBasePath, false, true, false);
     SS_ClassLoader::instance()->pushManifest($classManifest);
     $this->originalLocale = i18n::get_locale();
     // 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('adapter' => 'i18nSSLegacyAdapter', 'locale' => i18n::default_locale(), 'disableNotices' => true));
     i18n::register_translator($adapter, 'core');
     $adapter->removeCache();
     i18n::include_by_locale('en');
 }
Esempio n. 4
0
 public function testIncludeByLocaleWithoutFallbackLanguage()
 {
     $classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
     SS_ClassLoader::instance()->pushManifest($classManifest);
     $adapter = i18n::get_translator('core')->getAdapter();
     $this->assertTrue($adapter->isAvailable('en'));
     $this->assertFalse($adapter->isAvailable('mi'));
     // not defined at all
     $this->assertFalse($adapter->isAvailable('mi_NZ'));
     // defined, but not loaded yet
     $this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'mi'), 'Existing unloaded entity not available before call');
     $this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'mi_NZ'), 'Non-existing unloaded entity not available before call');
     i18n::include_by_locale('mi_NZ');
     $this->assertFalse($adapter->isAvailable('mi'));
     $this->assertTrue($adapter->isAvailable('mi_NZ'));
     $this->assertTrue($adapter->isTranslated('i18nTestModule.ENTITY', null, 'mi_NZ'), 'Includes module files');
     SS_ClassLoader::instance()->popManifest();
 }
Esempio n. 5
0
	function testIncludeByLocale() {
		// Looping through modules, so we can test the translation autoloading
		// Load non-exclusive to retain core class autoloading
		$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
		SS_ClassLoader::instance()->pushManifest($classManifest);
		
		$adapter = i18n::get_translator('core')->getAdapter();
		$this->assertTrue($adapter->isAvailable('en'));
		$this->assertFalse($adapter->isAvailable('de'));
		$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'de'), 
			'Existing unloaded entity not available before call'
		);
		$this->assertFalse($adapter->isTranslated('i18nTestModule.ENTITY', 'af'), 
			'Non-existing unloaded entity not available before call'
		);

		i18n::include_by_locale('de');
		
		$this->assertTrue($adapter->isAvailable('en'));
		$this->assertTrue($adapter->isAvailable('de'));
		$this->assertTrue($adapter->isTranslated('i18nTestModule.ENTITY', null, 'de'), 'Includes module files');
		$this->assertTrue($adapter->isTranslated('i18nTestTheme1.LAYOUTTEMPLATE', null, 'de'), 'Includes theme files');
		$this->assertTrue($adapter->isTranslated('i18nTestModule.OTHERENTITY', null, 'de'), 'Includes submodule files');
		
		SS_ClassLoader::instance()->popManifest();
	}