Skip to content

Commit

Permalink
[TASK] Make LocalizationUtilityTest notice free
Browse files Browse the repository at this point in the history
Releases: master
Resolves: #84281
Change-Id: Ibf5135a154c01bcd612f59a1ba9660f0f59fe5c6
Reviewed-on: https://review.typo3.org/56171
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
  • Loading branch information
janhelke authored and tmotyl committed Mar 15, 2018
1 parent 99a11af commit 70788c4
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions typo3/sysext/extbase/Tests/Unit/Utility/LocalizationUtilityTest.php
Expand Up @@ -15,8 +15,10 @@
*/

use Prophecy\Argument;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

Expand All @@ -26,16 +28,11 @@
class LocalizationUtilityTest extends UnitTestCase
{
/**
* Subject is not notice free, disable E_NOTICES
*/
protected static $suppressNotices = true;

/**
* Instance of configurationManager, injected to subject
* Instance of configurationManagerInterface, injected to subject
*
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
* @var ConfigurationManagerInterface
*/
protected $configurationManagerMock;
protected $configurationManagerInterfaceProphecy;

/**
* LOCAL_LANG array fixture
Expand Down Expand Up @@ -171,14 +168,14 @@ protected function setUp()

$reflectionClass = new \ReflectionClass(LocalizationUtility::class);

$this->configurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class, ['getConfiguration']);
$this->configurationManagerInterfaceProphecy = $this->prophesize(ConfigurationManagerInterface::class);
$property = $reflectionClass->getProperty('configurationManager');
$property->setAccessible(true);
$property->setValue($this->configurationManager);
$property->setValue($this->configurationManagerInterfaceProphecy->reveal());

$localizationFactoryProphecy = $this->prophesize(LocalizationFactory::class);
GeneralUtility::setSingletonInstance(LocalizationFactory::class, $localizationFactoryProphecy->reveal());
$localizationFactoryProphecy->getParsedData(Argument::cetera())->willReturn([]);
$localizationFactoryProphecy->getParsedData(Argument::cetera(), 'foo')->willReturn([]);
}

/**
Expand Down Expand Up @@ -260,7 +257,7 @@ public function translateForEmptyStringKeyWithArgumentsReturnsNull()
/**
* @return array
*/
public function translateDataProvider()
public function translateDataProvider(): array
{
return [
'get translated key' =>
Expand Down Expand Up @@ -309,10 +306,14 @@ public function translateTestWithBackendUserLanguage($key, $languageKey, $expect
$property->setAccessible(true);
$property->setValue($this->LOCAL_LANG);

$oldBackendUserLanguage = $GLOBALS['BE_USER']->uc['lang'];
$GLOBALS['BE_USER']->uc['lang'] = $languageKey;
$backendUserAuthenticationProphecy = $this->prophesize(BackendUserAuthentication::class);
$GLOBALS['BE_USER'] = $backendUserAuthenticationProphecy->reveal();
$backendUserAuthenticationProphecy->uc = [
'lang' => $languageKey,
];
$GLOBALS['LANG'] = $this->LOCAL_LANG;

$this->assertEquals($expected, LocalizationUtility::translate($key, 'core', $arguments, null, $altLanguageKeys));
$GLOBALS['BE_USER']->uc['lang'] = $oldBackendUserLanguage;
}

/**
Expand All @@ -331,14 +332,14 @@ public function translateTestWithExplicitLanguageParameters($key, $languageKey,
$property = $reflectionClass->getProperty('LOCAL_LANG');
$property->setAccessible(true);
$property->setValue($this->LOCAL_LANG);

$GLOBALS['LANG'] = $this->LOCAL_LANG;
$this->assertEquals($expected, LocalizationUtility::translate($key, 'core', $arguments, $languageKey, $altLanguageKeys));
}

/**
* @return array
*/
public function loadTypoScriptLabelsProvider()
public function loadTypoScriptLabelsProvider(): array
{
return [
'override labels with typoscript' => [
Expand Down Expand Up @@ -445,8 +446,11 @@ public function loadTypoScriptLabels(array $LOCAL_LANG, array $typoScriptLocalLa
$property->setAccessible(true);
$property->setValue($LOCAL_LANG);

$configurationType = \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
$this->configurationManager->expects($this->at(0))->method('getConfiguration')->with($configurationType, 'core', null)->will($this->returnValue($typoScriptLocalLang));
$configurationType = ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
$this->configurationManagerInterfaceProphecy
->getConfiguration($configurationType, 'core', null)
->shouldBeCalled()
->willReturn($typoScriptLocalLang);

$method = $reflectionClass->getMethod('loadTypoScriptLabels');
$method->setAccessible(true);
Expand Down Expand Up @@ -478,13 +482,18 @@ public function clearLabelWithTypoScript()
]
];

$configurationType = \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
$this->configurationManager->expects($this->at(0))->method('getConfiguration')->with($configurationType, 'core', null)->will($this->returnValue($typoScriptLocalLang));
$configurationType = ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK;
$this->configurationManagerInterfaceProphecy
->getConfiguration($configurationType, 'core', null)
->shouldBeCalled()
->willReturn($typoScriptLocalLang);

$method = $reflectionClass->getMethod('loadTypoScriptLabels');
$method->setAccessible(true);
$method->invoke(null, 'core', $this->languageFilePath);

$GLOBALS['LANG'] = $this->LOCAL_LANG;

$result = LocalizationUtility::translate('key1', 'core', null, 'dk');
$this->assertNotNull($result);
$this->assertEquals('', $result);
Expand Down

0 comments on commit 70788c4

Please sign in to comment.