[BUGFIX] Fix frontend unit tests if executed standalone 60/30560/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Wed, 4 Jun 2014 14:23:07 +0000 (16:23 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Wed, 4 Jun 2014 16:16:03 +0000 (18:16 +0200)
* Allow HTTP_HOST access for all unit tests
* Remove allow all in data provider

The latter implicitly caused a global allow, as PHPUint parses
all data providers before any test is run, thus setting globals there
will cause them to be preserved (and restored when backup globals is true).

Releases: 6.2, 6.1, 6.0
Resolves: #59343
Change-Id: I646294bb472027e22d6edc0622068698fe9a88fc
Reviewed-on: https://review.typo3.org/30560
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Build/UnitTestsBootstrap.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 074aeff..8c33c4e 100644 (file)
@@ -96,6 +96,10 @@ require PATH_site . '/typo3/sysext/core/Classes/Core/Bootstrap.php';
 $configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
 $GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
 
+// Avoid failing tests that rely on HTTP_HOST retrieval
+// TODO: Check if we could do better mocking in these tests
+$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
+
 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
        ->disableCoreAndClassesCache()
        ->initializeCachingFramework()
index 925645e..abd8382 100644 (file)
@@ -1749,10 +1749,9 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         * @dataProvider hostnamesNotMatchingTrustedHostsConfigurationDataProvider
         */
-       public function getIndpEnvForHostAllowsAllHostnameValuesOfDefaultConfiguration($httpHost, $hostNamePattern) {
+       public function getIndpEnvForHostAllowsAllHostnameValuesIfHostPatternIsSetToAllowAll($httpHost, $hostNamePattern) {
                $_SERVER['HTTP_HOST'] = $httpHost;
-               // DefaultConfiguration is currently applied for tests. In case this is changed, this test needs to be adapted.
-               // $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '/.*/';
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = Utility\GeneralUtility::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL;
                $this->assertSame($httpHost, Utility\GeneralUtility::getIndpEnv('HTTP_HOST'));
        }
 
@@ -1985,7 +1984,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @return array Valid url
         */
        public function sanitizeLocalUrlValidUrlDataProvider() {
-               $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = Utility\GeneralUtility::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL;
                $subDirectory = Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
                $typo3SiteUrl = Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
                $typo3RequestHost = Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST');