TYPO3 CMS  TYPO3_6-2
LocallangXmlParserTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $parser;
28 
33 
37  protected $l10nPriority;
38 
39  protected static function getFixtureFilePath($filename) {
40  // We have to take the whole relative path as otherwise this test fails on Windows systems
41  return PATH_site . 'typo3/sysext/core/Tests/Unit/Localization/Parser/Fixtures/' . $filename;
42  }
43 
47  public function setUp() {
48  // Backup locallangXMLOverride and localization format priority
49  $this->locallangXMLOverride = $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
50  $this->l10nPriority = $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'];
51  $this->parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Parser\\LocallangXmlParser');
52 
53  $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xml';
54  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
55  // Clear localization cache
56  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
57  }
58 
62  public function tearDown() {
63  // Restore locallangXMLOverride and localization format priority
64  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = $this->locallangXMLOverride;
65  $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = $this->l10nPriority;
66  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
67  parent::tearDown();
68  }
69 
73  public function canParseLlxmlInEnglish() {
74  $LOCAL_LANG = $this->parser->getParsedData(self::getFixtureFilePath('locallang.xml'), 'default');
75  $this->assertArrayHasKey('default', $LOCAL_LANG, 'default key not found in $LOCAL_LANG');
76  $expectedLabels = array(
77  'label1' => 'This is label #1',
78  'label2' => 'This is label #2',
79  'label3' => 'This is label #3'
80  );
81  foreach ($expectedLabels as $key => $expectedLabel) {
82  $this->assertEquals($expectedLabel, $LOCAL_LANG['default'][$key][0]['target']);
83  }
84  }
85 
89  public function canParseLlxmlInMd5Code() {
90  $LOCAL_LANG = $this->parser->getParsedData(self::getFixtureFilePath('locallang.xml'), 'md5');
91  $this->assertArrayHasKey('md5', $LOCAL_LANG, 'md5 key not found in $LOCAL_LANG');
92  $expectedLabels = array(
93  'label1' => '409a6edbc70dbeeccbfe5f1e569d6717',
94  'label2' => 'b5dc71ae9f52ecb9e7704c50562e39b0',
95  'label3' => '51eac55fa5ca15789ce9bbb0cf927296'
96  );
97  foreach ($expectedLabels as $key => $expectedLabel) {
98  $this->assertEquals($expectedLabel, $LOCAL_LANG['md5'][$key][0]['target']);
99  }
100  }
101 
106  $LOCAL_LANG = $this->parser->getParsedData(self::getFixtureFilePath('locallangOnlyDefaultLanguage.xml'), 'fr');
107  $expectedLabels = array(
108  'label1' => NULL,
109  'label2' => NULL,
110  'label3' => NULL
111  );
112  foreach ($expectedLabels as $key => $expectedLabel) {
113  $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
114  }
115  }
116 
120  public function canOverrideLlxml() {
121  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'][self::getFixtureFilePath('locallang.xml')][] = self::getFixtureFilePath('locallang_override.xml');
122  $LOCAL_LANG = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile(self::getFixtureFilePath('locallang.xml'), 'default'), \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile(self::getFixtureFilePath('locallang.xml'), 'md5'));
123  $this->assertArrayHasKey('default', $LOCAL_LANG, 'default key not found in $LOCAL_LANG');
124  $this->assertArrayHasKey('md5', $LOCAL_LANG, 'md5 key not found in $LOCAL_LANG');
125  $expectedLabels = array(
126  'default' => array(
127  'label1' => 'This is my 1st label',
128  'label2' => 'This is my 2nd label',
129  'label3' => 'This is label #3'
130  ),
131  'md5' => array(
132  'label1' => '409a6edbc70dbeeccbfe5f1e569d6717',
133  'label2' => 'b5dc71ae9f52ecb9e7704c50562e39b0',
134  'label3' => '51eac55fa5ca15789ce9bbb0cf927296'
135  )
136  );
137  foreach ($expectedLabels as $languageKey => $expectedLanguageLabels) {
138  foreach ($expectedLanguageLabels as $key => $expectedLabel) {
139  $this->assertEquals($expectedLabel, $LOCAL_LANG[$languageKey][$key][0]['target']);
140  }
141  }
142  }
143 
144  public function numericKeysDataProvider() {
145  $LOCAL_LANG = \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile(self::getFixtureFilePath('locallangNumericKeys.xml'), 'default');
146  $translations = array();
147 
148  foreach ($LOCAL_LANG['default'] as $key => $labelData) {
149  $translations['Numerical key ' . $key] = array($key, $labelData[0]['source'] . ' [FR]');
150  }
151 
152  return $translations;
153  }
154 
159  public function canTranslateNumericKeys($key, $expectedResult) {
160  $LOCAL_LANG = \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile(self::getFixtureFilePath('locallangNumericKeys.xml'), 'fr');
161 
162  $this->assertEquals($expectedResult, $LOCAL_LANG['fr'][$key][0]['target']);
163  }
164 
165 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]