‪TYPO3CMS  11.5
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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
27 use TYPO3\CMS\Core\Package\PackageManager;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 class ‪LocalizationFactoryTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
38  {
39  $languageStoreProphecy = $this->prophesize(LanguageStore::class);
40  $languageStoreProphecy->hasData(Argument::cetera())->willReturn(false);
41  $languageStoreProphecy->getData(Argument::cetera())->willReturn(['default' => []]);
42  $languageStoreProphecy->setData(Argument::cetera())->shouldBeCalled();
43  $languageStoreProphecy->setConfiguration(Argument::cetera())->willThrow(new ‪FileNotFoundException('testing', 1476049512));
44  $languageStoreProphecy->getFileReferenceWithoutExtension(Argument::cetera())->willReturn('');
45  $languageStoreProphecy->getSupportedExtensions()->willReturn([]);
46  $languageStoreProphecy->getDataByLanguage(Argument::cetera())->willReturn([]);
47 
48  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
49  $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
50  $cacheFrontendProphecy->set(Argument::cetera())->shouldBeCalled();
51 
52  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
53  $cacheManagerProphecy->getCache('l10n')->willReturn($cacheFrontendProphecy->reveal());
54 
55  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = ['foo' => 'bar'];
56 
57  (new ‪LocalizationFactory($languageStoreProphecy->reveal(), $cacheManagerProphecy->reveal()))
58  ->getParsedData(__DIR__ . '/Fixtures/locallang.invalid', 'default');
59  }
60 
64  public function ‪ensureLocalizationIsProperlyCached(): void
65  {
66  $packageManagerProphecy = $this->prophesize(PackageManager::class);
67  $packageManagerProphecy->extractPackageKeyFromPackagePath('EXT:core/Tests/Unit/Localization/Fixtures/locallang.xlf')->willReturn('core');
68 
69  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
70  $cacheFrontendProphecy->get(Argument::type('string'))->shouldBeCalled()->willReturn(false);
71  $cacheFrontendProphecy->set(Argument::type('string'), Argument::exact([
72  'label1' => [['source' => 'This is label #1', 'target' => 'This is label #1']],
73  ]))->shouldBeCalled()->willReturn(null);
74 
75  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
76  $cacheManagerProphecy->getCache('l10n')->willReturn($cacheFrontendProphecy->reveal());
77 
78  (new ‪LocalizationFactory(new ‪LanguageStore($packageManagerProphecy->reveal()), $cacheManagerProphecy->reveal()))
79  ->getParsedData('EXT:core/Tests/Unit/Localization/Fixtures/locallang.xlf', 'default');
80  }
81 }
‪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:36
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest
Definition: LocalizationFactoryTest.php:31
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:29
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest\ensureLocalizationIsProperlyCached
‪ensureLocalizationIsProperlyCached()
Definition: LocalizationFactoryTest.php:63
‪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: LocalesTest.php:18