‪TYPO3CMS  9.5
XliffParserTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Prophecy\Argument;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪XliffParserTest extends UnitTestCase
30 {
34  protected ‪$xliffFileNames;
35 
39  protected function ‪setUp()
40  {
41  // We have to take the whole relative path as otherwise this test fails on Windows systems
42  $fixturePath = ‪Environment::getFrameworkBasePath() . '/core/Tests/Unit/Localization/Parser/Fixtures/';
43  $this->xliffFileNames = [
44  'locallang' => $fixturePath . 'locallang.xlf',
45  'locallang_override' => $fixturePath . 'locallang_override.xlf',
46  'locallang_override_fr' => $fixturePath . 'fr.locallang_override.xlf'
47  ];
48  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xlf';
49 
50  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
51  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
52  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
53  $cacheManagerProphecy->getCache('l10n')->willReturn($cacheFrontendProphecy->reveal());
54  $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
55  $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
56  $cacheFrontendProphecy->flush()->willReturn(null);
57  }
58 
62  protected function ‪tearDown()
63  {
64  GeneralUtility::purgeInstances();
65  parent::tearDown();
66  }
67 
71  public function ‪canParseXliffInEnglish()
72  {
73  $LOCAL_LANG = (new ‪XliffParser)->getParsedData($this->xliffFileNames['locallang'], 'default');
74  $this->assertArrayHasKey('default', $LOCAL_LANG, 'default key not found in $LOCAL_LANG');
75  $expectedLabels = [
76  'label1' => 'This is label #1',
77  'label2' => 'This is label #2',
78  'label3' => 'This is label #3'
79  ];
80  foreach ($expectedLabels as $key => $expectedLabel) {
81  $this->assertEquals($expectedLabel, $LOCAL_LANG['default'][$key][0]['target']);
82  }
83  }
84 
88  public function ‪canParseXliffInFrench()
89  {
90  $LOCAL_LANG = (new ‪XliffParser)->getParsedData($this->xliffFileNames['locallang'], 'fr');
91  $this->assertArrayHasKey('fr', $LOCAL_LANG, 'fr key not found in $LOCAL_LANG');
92  $expectedLabels = [
93  'label1' => 'Ceci est le libellé no. 1',
94  'label2' => 'Ceci est le libellé no. 2',
95  'label3' => 'Ceci est le libellé no. 3'
96  ];
97  foreach ($expectedLabels as $key => $expectedLabel) {
98  $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
99  }
100  }
101 
105  public function ‪canOverrideXliff()
106  {
108  $factory = new ‪LocalizationFactory;
109 
110  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override'];
111  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['fr'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override_fr'];
112  $LOCAL_LANG = array_merge(
113  $factory->getParsedData($this->xliffFileNames['locallang'], 'default'),
114  $factory->getParsedData($this->xliffFileNames['locallang'], 'fr')
115  );
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 = [
119  'default' => [
120  'label1' => 'This is my 1st label',
121  'label2' => 'This is my 2nd label',
122  'label3' => 'This is label #3'
123  ],
124  'fr' => [
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  {
146  $factory = new ‪LocalizationFactory;
147 
148  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['fr'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override_fr'];
149  $LOCAL_LANG = $factory->getParsedData($this->xliffFileNames['locallang'], 'fr');
150  $this->assertArrayHasKey('fr', $LOCAL_LANG, 'fr key not found in $LOCAL_LANG');
151  $expectedLabels = [
152  'label1' => 'Ceci est mon 1er libellé',
153  'label2' => 'Ceci est le libellé no. 2',
154  'label3' => 'Ceci est mon 3e libellé'
155  ];
156  foreach ($expectedLabels as $key => $expectedLabel) {
157  $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
158  }
159  }
160 }
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\canOverrideXliffWithFrenchOnly
‪canOverrideXliffWithFrenchOnly()
Definition: XliffParserTest.php:142
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:25
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\canParseXliffInFrench
‪canParseXliffInFrench()
Definition: XliffParserTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser
Definition: LocallangXmlParserTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\canOverrideXliff
‪canOverrideXliff()
Definition: XliffParserTest.php:104
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\$xliffFileNames
‪array $xliffFileNames
Definition: XliffParserTest.php:33
‪TYPO3\CMS\Core\Core\Environment\getFrameworkBasePath
‪static string getFrameworkBasePath()
Definition: Environment.php:234
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest
Definition: XliffParserTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\canParseXliffInEnglish
‪canParseXliffInEnglish()
Definition: XliffParserTest.php:70
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\setUp
‪setUp()
Definition: XliffParserTest.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Localization\Parser\XliffParser
Definition: XliffParser.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\tearDown
‪tearDown()
Definition: XliffParserTest.php:61