[TASK] Add missing unit tests for SilentConfigurationUpgradeService (4) 45/42545/7
authorMichael Oehlhof <typo3@oehlhof.de>
Wed, 12 Aug 2015 17:56:20 +0000 (19:56 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 16 Aug 2015 16:55:13 +0000 (18:55 +0200)
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 <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php

index ae816a2..fab970d 100644 (file)
@@ -346,6 +346,77 @@ class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTe
        }
 
        /**
+        * @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
         *
         * @return array