‪TYPO3CMS  ‪main
LocalizationFactoryTest.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\Test;
26 use TYPO3\CMS\Core\Package\PackageManager;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪LocalizationFactoryTest extends UnitTestCase
30 {
31  #[Test]
33  {
34  $languageStoreMock = $this->createMock(LanguageStore::class);
35  $languageStoreMock->method('hasData')->with(self::anything())->willReturn(false);
36  $languageStoreMock->method('getData')->with(self::anything())->willReturn(['default' => []]);
37  $languageStoreMock->expects(self::atLeastOnce())->method('setData')->with(self::anything());
38  $languageStoreMock->method('setConfiguration')->with(self::anything())->willThrowException(new ‪FileNotFoundException('testing', 1476049512));
39  $languageStoreMock->method('getFileReferenceWithoutExtension')->with(self::anything())->willReturn('');
40  $languageStoreMock->method('getSupportedExtensions')->willReturn([]);
41  $languageStoreMock->method('getDataByLanguage')->with(self::anything())->willReturn([]);
42 
43  $cacheFrontendMock = $this->createMock(FrontendInterface::class);
44  $cacheFrontendMock->method('get')->with(self::anything())->willReturn(false);
45  $cacheFrontendMock->expects(self::atLeastOnce())->method('set')->with(self::anything());
46 
47  $cacheManagerMock = $this->createMock(CacheManager::class);
48  $cacheManagerMock->method('getCache')->with('l10n')->willReturn($cacheFrontendMock);
49 
50  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = ['foo' => 'bar'];
51 
52  (new ‪LocalizationFactory($languageStoreMock, $cacheManagerMock))
53  ->getParsedData(__DIR__ . '/Fixtures/locallang.invalid', 'default');
54  }
55 
56  #[Test]
57  public function ‪ensureLocalizationIsProperlyCached(): void
58  {
59  $packageManagerMock = $this->createMock(PackageManager::class);
60  $packageManagerMock->method('extractPackageKeyFromPackagePath')->with('EXT:core/Tests/Unit/Localization/Fixtures/locallang.xlf')->willReturn('core');
61 
62  $cacheFrontendMock = $this->createMock(FrontendInterface::class);
63  $cacheFrontendMock->expects(self::atLeastOnce())->method('get')->with(self::isType('string'))->willReturn(false);
64  $cacheFrontendMock->expects(self::atLeastOnce())->method('set')->with(self::isType('string'), [
65  'label1' => [['source' => 'This is label #1', 'target' => 'This is label #1']],
66  ])->willReturn(null);
67 
68  $cacheManagerMock = $this->createMock(CacheManager::class);
69  $cacheManagerMock->method('getCache')->with('l10n')->willReturn($cacheFrontendMock);
70 
71  (new ‪LocalizationFactory(new ‪LanguageStore($packageManagerMock), $cacheManagerMock))
72  ->getParsedData('EXT:core/Tests/Unit/Localization/Fixtures/locallang.xlf', 'default');
73  }
74 }
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:31
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:21
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest\getParsedDataCallsLocalizationOverrideIfFileNotFoundExceptionIsThrown
‪getParsedDataCallsLocalizationOverrideIfFileNotFoundExceptionIsThrown()
Definition: LocalizationFactoryTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest
Definition: LocalizationFactoryTest.php:30
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:31
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest\ensureLocalizationIsProperlyCached
‪ensureLocalizationIsProperlyCached()
Definition: LocalizationFactoryTest.php:57
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Localization
Definition: DateFormatterTest.php:18