TYPO3 CMS  TYPO3_6-2
XliffParserTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $parser;
28 
33 
37  protected $l10nPriority;
38 
42  protected $xliffFileNames;
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\\XliffParser');
52 
53  // We have to take the whole relative path as otherwise this test fails on Windows systems
54  $fixturePath = PATH_site . 'typo3/sysext/core/Tests/Unit/Localization/Parser/Fixtures/';
55  $this->xliffFileNames = array(
56  'locallang' => $fixturePath . 'locallang.xlf',
57  'locallang_override' => $fixturePath . 'locallang_override.xlf',
58  'locallang_override_fr' => $fixturePath . 'fr.locallang_override.xlf'
59  );
60  $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xlf';
61  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
62  // Clear localization cache
63  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
64  }
65 
69  public function tearDown() {
70  // Restore locallangXMLOverride and localization format priority
71  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = $this->locallangXMLOverride;
72  $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = $this->l10nPriority;
73  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
74  parent::tearDown();
75  }
76 
80  public function canParseXliffInEnglish() {
81  $LOCAL_LANG = $this->parser->getParsedData($this->xliffFileNames['locallang'], 'default');
82  $this->assertArrayHasKey('default', $LOCAL_LANG, 'default key not found in $LOCAL_LANG');
83  $expectedLabels = array(
84  'label1' => 'This is label #1',
85  'label2' => 'This is label #2',
86  'label3' => 'This is label #3'
87  );
88  foreach ($expectedLabels as $key => $expectedLabel) {
89  $this->assertEquals($expectedLabel, $LOCAL_LANG['default'][$key][0]['target']);
90  }
91  }
92 
96  public function canParseXliffInFrench() {
97  $LOCAL_LANG = $this->parser->getParsedData($this->xliffFileNames['locallang'], 'fr');
98  $this->assertArrayHasKey('fr', $LOCAL_LANG, 'fr key not found in $LOCAL_LANG');
99  $expectedLabels = array(
100  'label1' => 'Ceci est le libellé no. 1',
101  'label2' => 'Ceci est le libellé no. 2',
102  'label3' => 'Ceci est le libellé no. 3'
103  );
104  foreach ($expectedLabels as $key => $expectedLabel) {
105  $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
106  }
107  }
108 
112  public function canOverrideXliff() {
113  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override'];
114  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['fr'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override_fr'];
115  $LOCAL_LANG = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile($this->xliffFileNames['locallang'], 'default'), \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile($this->xliffFileNames['locallang'], 'fr'));
116  $this->assertArrayHasKey('default', $LOCAL_LANG, 'default key not found in $LOCAL_LANG');
117  $this->assertArrayHasKey('fr', $LOCAL_LANG, 'fr key not found in $LOCAL_LANG');
118  $expectedLabels = array(
119  'default' => array(
120  'label1' => 'This is my 1st label',
121  'label2' => 'This is my 2nd label',
122  'label3' => 'This is label #3'
123  ),
124  'fr' => array(
125  'label1' => 'Ceci est mon 1er libellé',
126  'label2' => 'Ceci est le libellé no. 2',
127  'label3' => 'Ceci est mon 3e libellé'
128  )
129  );
130  foreach ($expectedLabels as $languageKey => $expectedLanguageLabels) {
131  foreach ($expectedLanguageLabels as $key => $expectedLabel) {
132  $this->assertEquals($expectedLabel, $LOCAL_LANG[$languageKey][$key][0]['target']);
133  }
134  }
135  }
136 
143  public function canOverrideXliffWithFrenchOnly() {
144  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['fr'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override_fr'];
145  $LOCAL_LANG = \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile($this->xliffFileNames['locallang'], 'fr');
146  $this->assertArrayHasKey('fr', $LOCAL_LANG, 'fr key not found in $LOCAL_LANG');
147  $expectedLabels = array(
148  'label1' => 'Ceci est mon 1er libellé',
149  'label2' => 'Ceci est le libellé no. 2',
150  'label3' => 'Ceci est mon 3e libellé'
151  );
152  foreach ($expectedLabels as $key => $expectedLabel) {
153  $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
154  }
155  }
156 
157 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]