‪TYPO3CMS  9.5
LocalizationFactoryTest.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;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪LocalizationFactoryTest extends UnitTestCase
32 {
33  public function ‪tearDown()
34  {
35  // Drop created singletons again
36  GeneralUtility::purgeInstances();
37  parent::tearDown();
38  }
39 
44  {
45  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
46  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
47  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
48  $cacheManagerProphecy->getCache('l10n')->willReturn($cacheFrontendProphecy->reveal());
49  $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
50  $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
51 
52  $subject = new ‪LocalizationFactory;
53 
54  $unique = 'locallangXMLOverrideTest' . substr($this->getUniqueId(), 0, 10);
55  $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
56  <T3locallang>
57  <data type="array">
58  <languageKey index="default" type="array">
59  <label index="buttons.logout">EXIT</label>
60  </languageKey>
61  </data>
62  </T3locallang>';
63  $file = ‪Environment::getVarPath() . '/tests/' . $unique . '.xml';
64  GeneralUtility::writeFileToTypo3tempDir($file, $xml);
65  $this->testFilesToDelete[] = $file;
66 
67  // Get default value
68  $defaultLL = $subject->getParsedData('EXT:core/Resources/Private/Language/locallang_core.xlf', 'default');
69 
70  // Set override file
71  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:core/Resources/Private/Language/locallang_core.xlf'][$unique] = $file;
72 
74  $store = GeneralUtility::makeInstance(LanguageStore::class);
75  $store->flushData('EXT:core/Resources/Private/Language/locallang_core.xlf');
76 
77  // Get override value
78  $overrideLL = $subject->getParsedData('EXT:core/Resources/Private/Language/locallang_core.xlf', 'default');
79 
80  $this->assertNotEquals($overrideLL['default']['buttons.logout'][0]['target'], '');
81  $this->assertNotEquals($defaultLL['default']['buttons.logout'][0]['target'], $overrideLL['default']['buttons.logout'][0]['target']);
82  $this->assertEquals($overrideLL['default']['buttons.logout'][0]['target'], 'EXIT');
83  }
84 
89  {
90  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
91  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
92 
94  $localizationFactory = $this->getAccessibleMock(LocalizationFactory::class, ['localizationOverride']);
95  $languageStore = $this->getMockBuilder(LanguageStore::class)
96  ->setMethods(['hasData', 'setConfiguration', 'getData', 'setData'])
97  ->getMock();
98  $cacheInstance = $this->getMockBuilder(VariableFrontend::class)
99  ->setMethods(['get', 'set'])
100  ->disableOriginalConstructor()
101  ->getMock();
102  $localizationFactory->_set('store', $languageStore);
103  $localizationFactory->_set('cacheInstance', $cacheInstance);
104  $languageStore->method('hasData')->willReturn(false);
105  $languageStore->method('getData')->willReturn(['default' => []]);
106  $languageStore->method('setConfiguration')->willThrowException(new ‪FileNotFoundException('testing', 1476049512));
107  $cacheInstance->method('get')->willReturn(false);
108  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = ['foo' => 'bar'];
109 
110  $localizationFactory->expects($this->once())->method('localizationOverride');
111  $localizationFactory->getParsedData('EXT:backend/Resources/Private/Language/locallang_layout.xlf', 'default');
112  }
113 }
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:25
‪TYPO3\CMS\Core\Localization\Exception\FileNotFoundException
Definition: FileNotFoundException.php:21
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest\getParsedDataCallsLocalizationOverrideIfFileNotFoundExceptionIsThrown
‪getParsedDataCallsLocalizationOverrideIfFileNotFoundExceptionIsThrown()
Definition: LocalizationFactoryTest.php:88
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest
Definition: LocalizationFactoryTest.php:32
‪TYPO3\CMS\Core\Localization\LanguageStore
Definition: LanguageStore.php:26
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:24
‪TYPO3\CMS\Core\Tests\Unit\Localization\LocalizationFactoryTest\getParsedDataHandlesLocallangXMLOverride
‪getParsedDataHandlesLocallangXMLOverride()
Definition: LocalizationFactoryTest.php:43
‪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\LocalizationFactoryTest\tearDown
‪tearDown()
Definition: LocalizationFactoryTest.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Localization
Definition: LocalesTest.php:2
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165