TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
LocalizationFactoryTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Localization;
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/var/tests/' . $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/Resources/Private/Language/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/Resources/Private/Language/locallang_core.xlf'][$unique] = $file;
53  $store = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageStore::class);
54  $store->flushData('EXT:lang/Resources/Private/Language/locallang_core.xlf');
55  // Get override value
56  $overrideLL = $subject->getParsedData('EXT:lang/Resources/Private/Language/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->getMockBuilder(\TYPO3\CMS\Core\Localization\LanguageStore::class)
72  ->setMethods(['hasData', 'setConfiguration', 'getData', 'setData'])
73  ->getMock();
74  $cacheInstance = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class)
75  ->setMethods(['get', 'set'])
76  ->disableOriginalConstructor()
77  ->getMock();
78  $localizationFactory->_set('store', $languageStore);
79  $localizationFactory->_set('cacheInstance', $cacheInstance);
80  $languageStore->method('hasData')->willReturn(false);
81  $languageStore->method('getData')->willReturn([]);
82  $languageStore->method('setConfiguration')->willThrowException(new \TYPO3\CMS\Core\Localization\Exception\FileNotFoundException('testing', 1476049512));
83  $cacheInstance->method('get')->willReturn(false);
84  $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] = ['foo' => 'bar'];
85 
86  $localizationFactory->expects($this->once())->method('localizationOverride');
87  $localizationFactory->getParsedData('EXT:backend/Resources/Private/Language/locallang_layout.xlf', 'default');
88  }
89 }
static writeFileToTypo3tempDir($filepath, $content)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)