From aed988486252808507cf97d6b75efe66302df7f3 Mon Sep 17 00:00:00 2001 From: Michael Oehlhof Date: Wed, 12 Aug 2015 19:56:20 +0200 Subject: [PATCH] [TASK] Add missing unit tests for SilentConfigurationUpgradeService (4) Missing unit tests for generateEncryptionKeyIfNeeded() are added. Resolves: #68996 Releases: master Change-Id: Ia9c88be6dfdef1d7269960f39a17bccedf25ff69 Reviewed-on: http://review.typo3.org/42545 Reviewed-by: Markus Klein Tested-by: Markus Klein Reviewed-by: Stefan Neufeind Tested-by: Stefan Neufeind --- .../SilentConfigurationUpgradeServiceTest.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php b/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php index ae816a29c934..fab970d57007 100644 --- a/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php +++ b/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php @@ -345,6 +345,77 @@ class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTe $silentConfigurationUpgradeServiceInstance->_call('setProxyAuthScheme'); } + /** + * @test + */ + public function doNotGenerateEncryptionKeyIfExists() { + /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */ + $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock( + \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class, + array('dummy'), + array(), + '', + FALSE + ); + + $currentLocalConfiguration = array( + array('SYS/encryptionKey', 'EnCrYpTiOnKeY') + ); + + $this->createConfigurationManagerWithMockedMethods( + array( + 'getLocalConfigurationValueByPath', + 'setLocalConfigurationValueByPath', + ) + ); + $this->configurationManager->expects($this->exactly(1)) + ->method('getLocalConfigurationValueByPath') + ->will($this->returnValueMap($currentLocalConfiguration)); + $this->configurationManager->expects($this->never()) + ->method('setLocalConfigurationValueByPath'); + + $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager); + + $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded'); + } + + /** + * @test + */ + public function generateEncryptionKeyIfNotExists() { + /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */ + $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock( + \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class, + array('dummy'), + array(), + '', + FALSE + ); + + $closure = function () { + throw new \RuntimeException('Path does not exist in array', 1341397869); + }; + + $this->createConfigurationManagerWithMockedMethods( + array( + 'getLocalConfigurationValueByPath', + 'setLocalConfigurationValueByPath', + ) + ); + $this->configurationManager->expects($this->exactly(1)) + ->method('getLocalConfigurationValueByPath') + ->will($this->returnCallback($closure)); + $this->configurationManager->expects($this->once()) + ->method('setLocalConfigurationValueByPath') + ->with($this->equalTo('SYS/encryptionKey'), $this->isType('string')); + + $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class); + + $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager); + + $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded'); + } + /** * Dataprovider for transferDeprecatedCurlSettings * -- 2.20.1