TYPO3 CMS  TYPO3_7-6
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 
19 
24 {
28  public function getParsedDataHandlesLocallangXMLOverride()
29  {
31  $subject = new LocalizationFactory;
32 
33  $unique = 'locallangXMLOverrideTest' . substr($this->getUniqueId(), 0, 10);
34  $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
35  <T3locallang>
36  <data type="array">
37  <languageKey index="default" type="array">
38  <label index="buttons.logout">EXIT</label>
39  </languageKey>
40  </data>
41  </T3locallang>';
42  $file = PATH_site . 'typo3temp/' . $unique . '.xml';
44  // Make sure there is no cached version of the label
45  GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('l10n')->flush();
46  // Get default value
47  $defaultLL = $subject->getParsedData('EXT:lang/locallang_core.xlf', 'default');
48  // Clear language cache again
49  GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('l10n')->flush();
50  // Set override file
51  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xlf'][$unique] = $file;
53  $store = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageStore::class);
54  $store->flushData('EXT:lang/locallang_core.xlf');
55  // Get override value
56  $overrideLL = $subject->getParsedData('EXT:lang/locallang_core.xlf', 'default');
57  // Clean up again
58  unlink($file);
59  $this->assertNotEquals($overrideLL['default']['buttons.logout'][0]['target'], '');
60  $this->assertNotEquals($defaultLL['default']['buttons.logout'][0]['target'], $overrideLL['default']['buttons.logout'][0]['target']);
61  $this->assertEquals($overrideLL['default']['buttons.logout'][0]['target'], 'EXIT');
62  }
63 
67  public function getParsedDataCallsLocalizationOverrideIfFileNotFoundExceptionIsThrown()
68  {
70  $localizationFactory = $this->getAccessibleMock(LocalizationFactory::class, ['localizationOverride']);
71  $languageStore = $this->getMock(\TYPO3\CMS\Core\Localization\LanguageStore::class, ['hasData', 'setConfiguration', 'getData', 'setData']);
72  $cacheInstance = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class, ['get', 'set'], [], '', false);
73  $localizationFactory->_set('store', $languageStore);
74  $localizationFactory->_set('cacheInstance', $cacheInstance);
75  $languageStore->method('hasData')->willReturn(false);
76  $languageStore->method('getData')->willReturn([]);
77  $languageStore->method('setConfiguration')->willThrowException(new \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException());
78  $cacheInstance->method('get')->willReturn(false);
79  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = ['foo' => 'bar'];
80 
81  $localizationFactory->expects($this->once())->method('localizationOverride');
82  $localizationFactory->getParsedData('EXT:backend/Resources/Private/Language/locallang_layout.xlf', 'default');
83  }
84 }
static writeFileToTypo3tempDir($filepath, $content)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']