‪TYPO3CMS  ‪main
XliffParserTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪XliffParserTest extends UnitTestCase
26 {
27  public static function ‪canParseXliffDataProvider(): \Generator
28  {
29  yield 'Can handle default' => [
30  'languageKey' => 'default',
31  'expectedLabels' => [
32  'label1' => 'This is label #1',
33  'label2' => 'This is label #2',
34  'label3' => 'This is label #3',
35  ],
36  'requireApprovedLocalizations' => false,
37  ];
38  yield 'Can handle translation with approved only' => [
39  'languageKey' => 'fr',
40  'expectedLabels' => [
41  'label2' => 'Ceci est le libellé no. 2 [approved]',
42  ],
43  'requireApprovedLocalizations' => true,
44  ];
45  yield 'Can handle translation with non approved' => [
46  'languageKey' => 'fr',
47  'expectedLabels' => [
48  'label1' => 'Ceci est le libellé no. 1',
49  'label2' => 'Ceci est le libellé no. 2 [approved]',
50  'label3' => 'Ceci est le libellé no. 3 [not approved]',
51  ],
52  'requireApprovedLocalizations' => false,
53  ];
54  }
55 
56  #[DataProvider('canParseXliffDataProvider')]
57  #[Test]
58  public function ‪canParseXliff(string $languageKey, array $expectedLabels, bool $requireApprovedLocalizations): void
59  {
60  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['requireApprovedLocalizations'] = $requireApprovedLocalizations;
61  $LOCAL_LANG = (new ‪XliffParser())->getParsedData(__DIR__ . '/Fixtures/locallang.xlf', $languageKey);
62  self::assertArrayHasKey($languageKey, $LOCAL_LANG, sprintf('%s key not found in $LOCAL_LANG', $languageKey));
63  foreach ($expectedLabels as $key => $expectedLabel) {
64  self::assertEquals($expectedLabel, $LOCAL_LANG[$languageKey][$key][0]['target']);
65  }
66  }
67 }
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\canParseXliffDataProvider
‪static canParseXliffDataProvider()
Definition: XliffParserTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser
Definition: XliffParserTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest
Definition: XliffParserTest.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Localization\Parser\XliffParserTest\canParseXliff
‪canParseXliff(string $languageKey, array $expectedLabels, bool $requireApprovedLocalizations)
Definition: XliffParserTest.php:58
‪TYPO3\CMS\Core\Localization\Parser\XliffParser
Definition: XliffParser.php:25