[TASK] Add missing unit tests for SilentConfigurationUpgradeService (5) 32/42632/4
authorMichael Oehlhof <typo3@oehlhof.de>
Fri, 14 Aug 2015 19:55:29 +0000 (21:55 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 18 Aug 2015 18:10:19 +0000 (20:10 +0200)
Missing unit tests for configureBackendLoginSecurity() are added.

Resolves: #69075
Releases: master
Change-Id: I94898193d5e8bcee5ed5b99b5ac7e69a8a5787ea
Reviewed-on: http://review.typo3.org/42632
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php

index fab970d..f51bbf4 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Install\Service;
  */
 
 use TYPO3\CMS\Install\Controller\Exception\RedirectException;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+
 
 /**
  * Test case
@@ -37,6 +39,73 @@ class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTe
        }
 
        /**
+        * Dataprovider for configureBackendLoginSecurity
+        *
+        * @return array
+        */
+       public function configureBackendLoginSecurityLocalconfiguration() {
+               return array(
+                       array('', 'rsa', TRUE, FALSE),
+                       array('normal', 'rsa', TRUE, TRUE),
+                       array('rsa', 'normal', FALSE, TRUE),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider configureBackendLoginSecurityLocalconfiguration
+        */
+       public function configureBackendLoginSecurity($current, $setting, $isPackageActive, $hasLocalConfig) {
+               /** @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
+               );
+
+               /** @var $packageManager \TYPO3\CMS\Core\Package\PackageManager|\PHPUnit_Framework_MockObject_MockObject */
+               $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, array(), array(), '', FALSE);
+               $packageManager->expects($this->any())
+                       ->method('isPackageActive')
+                       ->will($this->returnValue($isPackageActive));
+               ExtensionManagementUtility::setPackageManager($packageManager);
+
+               $currentLocalConfiguration = array(
+                       array('BE/loginSecurityLevel', $current)
+               );
+               $closure = function () {
+                       throw new \RuntimeException('Path does not exist in array', 1341397869);
+               };
+
+               $this->createConfigurationManagerWithMockedMethods(
+                       array(
+                               'getLocalConfigurationValueByPath',
+                               'setLocalConfigurationValueByPath',
+                       )
+               );
+               if ($hasLocalConfig) {
+                       $this->configurationManager->expects($this->once())
+                               ->method('getLocalConfigurationValueByPath')
+                               ->will($this->returnValueMap($currentLocalConfiguration));
+               } else {
+                       $this->configurationManager->expects($this->once())
+                               ->method('getLocalConfigurationValueByPath')
+                               ->will($this->returnCallback($closure));
+               }
+               $this->configurationManager->expects($this->once())
+                       ->method('setLocalConfigurationValueByPath')
+                       ->with($this->equalTo('BE/loginSecurityLevel'), $this->equalTo($setting));
+
+               $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class);
+
+               $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
+
+               $silentConfigurationUpgradeServiceInstance->_call('configureBackendLoginSecurity');
+       }
+
+       /**
         * @test
         */
        public function removeObsoleteLocalConfigurationSettingsIfThereAreOldSettings() {